SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    0 Post(s)
    0 Thread(s)

    Moving Files From windows server 2003 to ftp using classic asp

    Hello Mate,

    I have a vb scripot function which will move files from my server to FTP.I have a problem in that ,which is the commands are not working and the files are not getting moved to the ftp .

    This is my code

    function sendToFtp(ftp_address,ftp_username,ftp_password,ftp_remote_directory,ftp_physical_path,ftp_files_to_put)
    Dim objFSO, objTextFile, oScript, oScriptNet, oFileSys, oFile, strCMD, strTempFile, strCommandResult

    'Dim ftp_address, ftp_username, ftp_password, ftp_physical_path, ftp_files_to_put
    ' Edit these variables to match your specifications
    'ftp_address = ""
    'ftp_username = "username"
    'ftp_password = "password"
    'ftp_remote_directory = "subdirectory" ' Leave blank if uploading to root directory
    'ftp_files_to_put = "file.txt"

    'On Error Resume Next
    Set oScript = Server.CreateObject("WSCRIPT.SHELL")
    Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Build our ftp-commands file
    FTPFILENAME = "test"&Year(Now())&Month(Now())&Day(Now())&Hour(Now())&Minute(Now())&Second(Now())&".ftp"
    Set objTextFile = objFSO.CreateTextFile(Server.MapPath("../MassUpload/" & FTPFILENAME))
    objTextFile.WriteLine "lcd " & chr(34)&Server.MapPath("../MassUpload/")&chr(34)
    objTextFile.WriteLine "open " & ftp_address
    objTextFile.WriteLine ftp_username
    objTextFile.WriteLine ftp_password

    ' Check to see if we need to issue a 'cd' command

    If ftp_remote_directory <> "" Then
    objTextFile.WriteLine "cd " & ftp_remote_directory
    End If

    objTextFile.WriteLine "prompt"
    objTextFile.WriteLine "binary"
    ' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the following line' objTextFile.WriteLine "binary"
    ' If there are multiple files to put, we need to use the command 'mput', instead of 'put'
    If Instr(1, ftp_files_to_put, "*",1) Then
    objTextFile.WriteLine "mput " & chr(34)&Server.MapPath("../MassUpload/" & ftp_files_to_put)&chr(34)
    objTextFile.WriteLine "put " & chr(34)&Server.MapPath("../MassUpload/" & ftp_files_to_put)&chr(34)
    End If
    objTextFile.WriteLine "bye"

    Set objTextFile = Nothing
    ' Use cmd.exe to run ftp.exe, parsing our newly created command file
    strCMD = "ftp.exe -s:" & chr(34)& Server.MapPath("../MassUpload/" & FTPFILENAME)& chr(34)
    'Response.Write strCMD


    'strTempFile = "C:\" & oFileSys.GetTempName( )
    strTempFile = Server.MapPath("../MassUpload/") & oFileSys.GetTempName( )
    Response.Write strTempFile
    ' Pipe output from cmd.exe to a temporary file (Not :| Steve)
    Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)
    Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)

    'On Error Resume Next
    'Grab output from temporary file
    strCommandResult = Server.HTMLEncode( oFile.ReadAll )
    ' Delete the temporary & ftp-command files
    ''Call oFileSys.DeleteFile( strTempFile, True )
    ''Call objFSO.DeleteFile( chr(34) & Server.MapPath("../MassUpload/" & FTPFILENAME)& chr(34), True )
    Set oFileSys = Nothing
    Set objFSO = Nothing
    ' Print result of FTP session to screen
    sendToFtp = strCommandResult
    End Function

    I have write permission to the MassUpload Folder .The file "test"&Year(Now())&Month(Now())&Day(Now())&Hour(Now())&Minute(Now())&Second(Now())&".ftp" is getting created and it has values correctly.

    but the temporary file (which wil have the result of the commands which are executing). is not getting created and even if create the temp file using CreateTextFile the got created but there is nothing in it.

    and when i write the commands (which will get executed ) i get the following.


    cmd.exe /c ftp.exe -s:"D:\MassUpload\testHBH2012431523.ftp" > "D:\MassUploadrad3D5F3.tmp"

    Please advise me on this issue.

    Thanks in advance,

  2. #2
    SitePoint Member knev's Avatar
    Join Date
    Nov 2010
    0 Post(s)
    0 Thread(s)
    check this link
    this should help you
    Maximize Traffic by Banner advertising
    Free fixes computer support


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts