We help IT Professionals succeed at work.

FTP a IMAGE to a webserver

Hello
I am using the following code to ftp files to a webserver.
It works except that when I send a .jpg file I can't open it.

Public Function TransferFileONE( _
    FileName As String, _
    LocalPath As String, _
    RemotePath As String, _
    ServerName As String, _
    UserName As String, _
    Password As String, _
    PushOrPull As PushOrPullConstants)

    On Error GoTo TransferFile_Err
   
    TransferFileONE = False
   
    Dim iFileNumber As Integer
    Dim strBatchFileName As String
    Dim strBatchFilePath As String
    Dim strFTPCommand As String
    Dim strFTPCommandFileName As String
    Dim strFTPCommandPath As String
    Dim strFTPCommandFile As String

        strBatchFileName = "FTPit.bat" ' pick a name ending in .bat
    strBatchFilePath = Environ("Temp") & "\" & strBatchFileName
    strFTPCommandFileName = "ftpcmds.txt" ' pick a name you like
    strFTPCommandPath = Environ("Temp") & "\" & strFTPCommandFileName
'    OpenFolder strFTPCommandPath
    ' define a batch file to transfer data between server to local machine
    strFTPCommand = "FTP -i -d -s:" & strFTPCommandPath
   
    strFTPCommandFile = "open " & ServerName & vbNewLine
    strFTPCommandFile = strFTPCommandFile & UserName & vbNewLine
    strFTPCommandFile = strFTPCommandFile & Password & vbNewLine
    strFTPCommandFile = strFTPCommandFile & "cd " & RemotePath & vbNewLine
    strFTPCommandFile = strFTPCommandFile & "lcd " & LocalPath & vbNewLine
    If PushOrPull = PushOrPullConstants.PullIt Then
        ' create ftp command file to pull data to remote machine
        strFTPCommandFile = strFTPCommandFile & "get " & LocalPath & FileName & vbNewLine
    Else 'PushOrPullConstants.PushIt
        ' create ftp command file to push data to remote machine
        strFTPCommandFile = strFTPCommandFile & "mput " & Chr(34) & LocalPath & FileName & Chr(34) & vbNewLine
'        strFTPCommandFile = strFTPCommandFile & "mput " & Chr(34) & FileName & Chr(34) & vbNewLine
    End If
    strFTPCommandFile = strFTPCommandFile & "binary " & vbNewLine
    strFTPCommandFile = strFTPCommandFile & "close" & vbNewLine
    strFTPCommandFile = strFTPCommandFile & "quit" & vbNewLine
   
    ' remove old FTP command file if it exists
    If Dir(strFTPCommandPath) <> "" Then
        Kill strFTPCommandPath
    End If
   
    ' create FTP command file
    iFileNumber = FreeFile()
    Open strFTPCommandPath For Output As #iFileNumber
    Print #iFileNumber, strFTPCommandFile
    Close #iFileNumber
   
    ' remove old batch file if it exists
    If Dir(strBatchFilePath) <> "" Then
        Kill strBatchFilePath
    End If
   
    ' create batch file to run FTP commands
    iFileNumber = FreeFile()
    Open strBatchFilePath For Output As #iFileNumber
    Print #iFileNumber, strFTPCommand
    Print #iFileNumber, "pause" ' take this out when it works as expected
    Close #iFileNumber
   
    Shell strBatchFilePath
'    OpenFolder strBatchFilePath

'    MsgBox "When the DOS window closes, the file transfer completed.", vbOKOnly Or vbInformation

TransferFile_Exit:
    Close #iFileNumber
    Exit Function
   
TransferFile_Err:
    MsgBox Err.Description
    Resume TransferFile_Exit
End Function


Attatched is a sample Image that has been sent to the server and downloaded again
2535.jpg
Comment
Watch Question

Commented:
I'm not in a good location to test this right now, but at my first look, you may want to try moving you binary command up above the push/pull...

strFTPCommandFile = strFTPCommandFile & "binary " & vbNewLine

looks like it should go  BEFORE:

If PushOrPull = PushOrPullConstants.PullIt Then


Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
That is no longer a JPEG.  It contains a lot of text about Canon and Adobe Photoshop.

It looks to me like you should be setting "binary" before the 'mput' command.  http://en.wikipedia.org/wiki/File_Transfer_Protocol  http://technet.microsoft.com/en-us/library/bb490668.aspx