FTP代码在客户端PC上不起作用

时间:2015-10-16 21:02:31

标签: vba excel-vba batch-file ftp excel

我有一个特定的VBA代码,FTP文件到一个位置。

    Function SendFtpFile_F(csvPath As Variant) As Boolean
    Dim rc As Integer
    Dim iFreeFile As Integer
    Dim sFTPUserID As String
    Dim sFTPPassWord As String
    Dim sWorkingDirectory As String
    Dim sFileToSend As String

    Const FTP_BATCH_FILE_NAME = "myFtpFile.ftp"
    Const INCREASED_BUFFER_SIZE = 20480

     fsheetname = ActiveSheet.Name

       Select Case fsheetname

      Case "Price Change"

       flocation = "price_change"

     Case "New SKU"

    flocation = "new_sku"

    Case "SKU Change"

      flocation = "sku_change"

      Case "Discontinuation"

       flocation = "sku_deletion"

     End Select


    SendFtpFile_F = False

   'csvPath = "C:\Users\10613527\Desktop\test\"
   csvPath = csvPath + "\"
    sWorkingDirectory = csvPath

    sFileToSend = Namex

    On Error GoTo FtpNECAFile_EH

    'Kill FTP process file if it exists
    If Dir(sWorkingDirectory & FTP_BATCH_FILE_NAME) <> "" Then
        Kill sWorkingDirectory & FTP_BATCH_FILE_NAME
    End If

    'Create FTP process file
    iFreeFile = FreeFile
    Open sWorkingDirectory & FTP_BATCH_FILE_NAME For Output As #iFreeFile
    Print #iFreeFile, "open " & FTP_ADDRESS
    Print #iFreeFile, FTP_USERID
    Print #iFreeFile, FTP_PASSWORD
    Print #iFreeFile, "ASCII"
    Print #iFreeFile, "CD " & flocation
    Print #iFreeFile, "put """ & sWorkingDirectory & sFileToSend & """"
    Print #iFreeFile, "bye"
    Close #iFreeFile

    'Shell command the FTP file to the server
    Shell "ftp -i -w:20480 -s:" & sWorkingDirectory & FTP_BATCH_FILE_NAME

    SendFtpFile_F = True

    GoTo FtpNECAFile_EX

    FtpNECAFile_EH:
        MsgBox "Err", Err.Name

    FtpNECAFile_EX:

     Exit Function


    End Function

此代码在我的机器中完美运行,但FTP部分在我的clienr机器中不起作用。

观察:当我运行此代码而不打印“BYE”命令然后在我的PC上我可以看到一个命令行弹出显示成功传输但在我的客户端PC中不会发生同样的情况。 cmd窗口甚至没有打开,我注意到FTP批处理文件完全没有问题。请帮忙。

2 个答案:

答案 0 :(得分:0)

文件现在正在运行,批处理文件似乎应该与输出文件位于同一位置,输出位置应该没有其他文件。

例如,您无法将文件保存在桌面中,如果目标目录中有大量文件,则shell扩展无法读取它。

FIX:在桌面上创建另一个文件夹并在那里保存文件然后执行FTP成功。

答案 1 :(得分:-2)

如果是我,我想我会在ftp文件本身切换PASV命令,看看客户端的防火墙是否阻止了这部分的数据部分。