0 votes
by (160 points)
edited

The instructions from our vendor require us to upload files using the following command in MS DOS FTP: PUT filename CUSTOMER_UPLD!FTP

Here's my attempt to do this using the rebex ftp component, but I get a 450 error returned: File Not Available. Please advise on how this command (CUSTOMER_UPLD!FTP) can be sent with the PutFile method of the ftp object. If the command is not sent, then the files just sit in the inbound directory of the remote server (likely a mainframe since it won't allow batch uploads) and are not picked up.

Sub UploadFTPFiles(ByVal LocalDir As String, ByVal User As String, ByVal Psw As String, ByVal Server As String, ByVal Port As Integer, ByVal FilePath As String)
    Dim client As New Ftp
    Dim FileDir As New DirectoryInfo(LocalDir)
    Dim fiClaimFiles() As FileInfo
    Dim fi As FileInfo
    Dim sArchPath As String

    AddHandler client.CommandSent, AddressOf client_CommandSent
    AddHandler client.ResponseRead, AddressOf client_ResponseRead

    With client
        .Connect(Server, Port)
        .Login(User, Psw)
        .TransferType = FtpTransferType.Binary
        .Passive = False
        fiClaimFiles = FileDir.GetFiles
        For Each fi In fiClaimFiles
            .PutFile(fi.FullName, FilePath + fi.Name + " CUSTOMER_UPLD!FTP")

            'Archive the file if sent successfully
            sArchPath = LocalDir + "Archive\" + fi.Name

            fi.MoveTo(sArchPath)
        Next
        .Disconnect()
    End With
End Sub
Applies to: Rebex FTP/SSL
by (73.6k points)
edited

Can you please send us the log file to support@rebex.net (it can be produced as described at http://www.rebex.net/kb/logging.aspx). It should contain the command sent to the server and the error response. We can tell more with this information.

1 Answer

0 votes
by (58.9k points)
edited

In release 2012 R3 we have added UploadCommand property for setting a custom upload command which will be sent when uploading a file to the FTP server instead of the default STOR command. It can be done as described in this post.

Your code would then look like this:

Sub UploadFTPFiles(ByVal LocalDir As String, ByVal User As String, ByVal Psw As String, ByVal Server As String, ByVal Port As Integer, ByVal FilePath As String)
    Dim client As New Ftp

    ' specify the command to be used for uploading to the FTP server:'
    client.Settings.UploadCommand = "PUT"

    Dim FileDir As New DirectoryInfo(LocalDir)
    Dim fiClaimFiles() As FileInfo
    Dim fi As FileInfo
    Dim sArchPath As String

    AddHandler client.CommandSent, AddressOf client_CommandSent
    AddHandler client.ResponseRead, AddressOf client_ResponseRead

    With client
        .Connect(Server, Port)
        .Login(User, Psw)
        .TransferType = FtpTransferType.Binary
        .Passive = False
        fiClaimFiles = FileDir.GetFiles
        For Each fi In fiClaimFiles
            .PutFile(fi.FullName, FilePath + fi.Name + " CUSTOMER_UPLD!FTP")

            'Archive the file if sent successfully'
            sArchPath = LocalDir + "Archive\" + fi.Name

            fi.MoveTo(sArchPath)
        Next
        .Disconnect()
    End With
End Sub
...