我有一個特定的VBA代碼,即FTPs文件到某個位置。FTP代碼無法在客戶端PC上工作
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部分在我的客戶機器中不起作用。
觀察:當我不打印「再見」命令,然後在我的電腦上運行該代碼,我可以看到一個命令行彈出顯示成功轉讓,但同樣沒有在我的客戶端PC發生。 cmd窗口甚至沒有打開,我注意到FTP的批處理文件寫得完全沒有問題。請幫忙。
嘗試設置ftp.exe的完整路徑。添加諸如'> c:\ temp \ error.log'之類的東西可能會存儲ftp.exe打印的任何錯誤消息以供以後查看。 – Marged
@Marged它寫入文件,創建它,我不知道如果我通過「設置完整路徑」得到你的意思謝謝 – Anarach
@Anarach,Windows FTP.exe文件存在的完整路徑。幾年前,我發生過這種情況,我們的計算機上安裝了第三方ftp程序,當我的代碼執行時,它首先從第三方程序中找到了ftp.exe,因爲它在PATH變量中更高。 – Squashman