我需要能够通过 VBA 进行 SFTP。我有一个 Access 程序,可以提取数据并对其进行操作,现在我必须找到一种通过 SFTP 上传 excel 07 文件的方法。
我在网上找了好几天了,还是没找到任何东西。我在这里看到了类似的主题How to use sftp from within an MS Access database module? ,我很想找到 Mat Nadrofsky,因为他似乎有一个解决方案,我只是无法理解其中任何一个)))))))))))
因此,如果有人可以解释该解决方案的含义或有不同的解决方案 - 我真的很感激 谢谢
最佳答案
在您链接的上一个 SO 答案中,Mat Nadrofsky 使用了 sftp 命令行客户端。在此示例中,我的 sftp 客户端是 pscp.exe。该客户端是 PuTTY 工具的一部分:PuTTY Download Page
我想构建并运行这样的命令,将 example.txt 复制到远程计算机上的主目录:
"C:\Program Files\PuTTY\pscp.exe" -sftp -l hans -pw changeme C:\Access\sample.txt 192.168.1.6:/home/hans/
因此此过程将构建并运行该命令字符串。
Public Sub SftpPut()
Const cstrSftp As String = """C:\Program Files\PuTTY\pscp.exe"""
Dim strCommand As String
Dim pUser As String
Dim pPass As String
Dim pHost As String
Dim pFile As String
Dim pRemotePath As String
pUser = "hans"
pPass = "changeme"
pHost = "192.168.1.6"
pFile = "C:\Access\sample.txt"
pRemotePath = "/home/hans/"
strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & _
" " & pFile & " " & pHost & ":" & pRemotePath
Debug.Print strCommand
Shell strCommand, 1 ' vbNormalFocus '
End Sub
您可能更喜欢ShellAndWait而不是壳牌,正如大卫·芬顿在对之前答案的评论中所建议的那样。
关于vba - 使用 VBA 进行 SFTP 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3754928/