在Excel中使用VBA将文本文件FTP到服务器 [英] FTP a text file to a server using VBA in Excel
本文介绍了在Excel中使用VBA将文本文件FTP到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
这是通过做一些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 =********
'ftp.exe的安装文件命令
fNum = FreeFile()
打开vPath& \FtpComm.txt输出为#fNum
打印#1,用户***** ***您的登录名和密码
打印#1,cd TargetDir '更改为服务器上的目录
打印#1,bin'bin或ascii文件类型发送
打印#1,put& vPath&\& vFile& ;& vFile将本地文件名上传到服务器文件
打印#1,关闭关闭连接
打印#1,退出退出ftp程序
关闭
Shellftp -n -i -g -s:& vPath&\FtpComm.txt& vFTPServ,vbNormalNoFocus
SetAttr vPath&\ FtpComm.txt,vbNormal
Kill vPath&\FtpComm.txt
End Sub
原始来源: http ://www.access-programmers.co.uk/forums/showthread.php?t = 184692
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.
解决方案
Here is a solution I found by doing some Google search -
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
这篇关于在Excel中使用VBA将文本文件FTP到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文