使用 Excel 中的 VBA 将文本文件通过 FTP 传输到服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2914647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FTP a text file to a server using VBA in Excel
提问by Anindya
I have an Excel worksheet where the user enters certain data, which I want to store in a text file and upload to a server using FTP. One site suggested adding a reference to "Microsoft Internet Transfer Control" and then define an "Inet" object to do the FTP. However, I am unable to find a reference with this name in "Tools -> References" in the VB Editor. Does anyone know of a solution for this problem? Thanks in advance.
我有一个 Excel 工作表,用户可以在其中输入某些数据,我想将这些数据存储在文本文件中并使用 FTP 上传到服务器。一个站点建议添加对“Microsoft Internet Transfer Control”的引用,然后定义一个“Inet”对象来执行 FTP。但是,我无法在 VB 编辑器的“工具 -> 引用”中找到具有此名称的引用。有谁知道这个问题的解决方案?提前致谢。
回答by Anindya
Here is a solution I found by doing some Google search -
这是我通过 Google 搜索找到的解决方案 -
Public Sub FtpSend()
Dim vPath As String
Dim vFile As String
Dim vFTPServ As String
Dim fNum As Long
vPath = ThisWorkbook.Path
vFile = "YourFile.csv"
vFTPServ = "********"
'Mounting file command for ftp.exe
fNum = FreeFile()
Open vPath & "\FtpComm.txt" For Output As #fNum
Print #1, "user ***** *****" ' your login and password"
Print #1, "cd TargetDir" 'change to dir on server
Print #1, "bin" ' bin or ascii file type to send
Print #1, "put " & vPath & "\" & vFile & " " & vFile ' upload local filename to server file
Print #1, "close" ' close connection
Print #1, "quit" ' Quit ftp program
Close
Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbNormalNoFocus
SetAttr vPath & "\FtpComm.txt", vbNormal
Kill vPath & "\FtpComm.txt"
End Sub
Original source: http://www.access-programmers.co.uk/forums/showthread.php?t=184692
原始来源:http: //www.access-programmers.co.uk/forums/showthread.php?t=184692