在 Excel 中使用 VBA 将文本文件通过 FTP 传输到服务器

标签 ftp excel vba

我有一个 Excel 工作表,用户在其中输入某些数据,我想将其存储在文本文件中并使用 FTP 上传到服务器。一个站点建议添加对“Microsoft Internet Transfer Control”的引用,然后定义一个“Inet”对象来执行 FTP。但是,我无法在 VB 编辑器的“工具 -> 引用”中找到具有此名称的引用。有谁知道这个问题的解决方案?提前致谢。

最佳答案

这是我通过 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

原始来源:http://www.access-programmers.co.uk/forums/showthread.php?t=184692

关于在 Excel 中使用 VBA 将文本文件通过 FTP 传输到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2914647/

相关文章:

python - 将 Excel 单元格值直接读取到复杂的 Python 对象,DataNitro

VBA 速度慢且不适用于较长的数据集

excel - If 语句公式破坏 VBA 循环代码

windows - 从 VBA 运行 command.com 或 cmd.exe 导致 MSG 命令出现问题

c# - FTP 目录列表返回为 HTML 而不是简单的 Linux ls 输出

java - 连接到 SOCKS5 代理以在 Java 中执行 FTP/S

java - maven 部署在 jre1.7 上失败

excel - 在不使用 VBA 或宏的情况下在 excel 中循环

c# - 如何在 C# 中使用线程来加快工作?

vba - Excel VBA DIR 仅循环一次