我希望你能在这里帮助我一些代码。我创建了一个模块,该模块创建一个 ftp 命令文件,然后是一个批处理文件来执行它。
我从另一个 StackOverflow 帖子中得到了这个过程: FTP a text file to a server using VBA in Excel
有时 test.txt 会出现在服务器上,但大多数时候不会。但是,ftp 提示总是报告传输成功。
Private Sub SendFileToServer()
Dim sCmdFile As String
Dim sBatFile As String
Dim vPath As String
Dim iFileNum As Integer
vPath = ThisWorkbook.Path
sCmdFile = vPath & "\" & "ftp" & "\" & "ftpCommand.txt"
iFileNum = FreeFile
Open sCmdFile For Output As iFileNum
Print #iFileNum, "open 555.555.555.55"
Print #iFileNum, "user username"
Print #iFileNum, "password"
Print #iFileNum, "hash"
Print #iFileNum, "ascii"
Print #iFileNum, "lcd " & vPath
Print #iFileNum, "cd dsi_Timesheets"
Print #iFileNum, "put " & vPath & "\" & "test.txt"
Print #1, "close"
Print #1, "quit"
Close #iFileNum
Shell "ftp -n -i -g -s:" & vPath & "\ftp" & "\ftpCommand.txt " & vFTPServ, vbNormalNoFocus
SetAttr vPath & "\ftp" & "\ftpCommand.txt", vbNormal
Kill vPath & "\ftp" & "\ftpCommand.txt"
End Sub
谢谢