使用 VBA 上传 SFTP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3754928/
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
SFTP upload with VBA
提问by lalachka
i need to be able to SFTP though VBA. I have an Access program that pulls data, manipulates it and now i have to find a way to upload the excel 07 file through SFTP.
我需要能够通过 VBA 进行 SFTP。我有一个 Access 程序可以提取数据并对其进行操作,现在我必须找到一种方法通过 SFTP 上传 excel 07 文件。
i've been looking on the net for days and can't find anything. I saw a similar topic here How to use sftp from within an MS Access database module?, and i'd love to find Mat Nadrofsky, because it seemed like he has a solution, i just cant understand any of it)))))))))))
我已经在网上找了几天,找不到任何东西。我在这里看到了一个类似的主题如何从 MS Access 数据库模块中使用 sftp?,我很想找到 Mat Nadrofsky,因为他似乎有一个解决方案,我就是无法理解))))))))))))
so if someone can explain what that solution was about or has a different solution - i'd really appreciate it thank you
因此,如果有人可以解释该解决方案是关于什么或有不同的解决方案 - 我真的很感激谢谢
回答by HansUp
In the previous SO answer you linked, Mat Nadrofsky used an sftp command line client. In this example my sftp client is pscp.exe. That client is part of the PuTTY tools: PuTTY Download Page
在您链接的上一个 SO 答案中,Mat Nadrofsky 使用了 sftp 命令行客户端。在这个例子中,我的 sftp 客户端是 pscp.exe。该客户端是 PuTTY 工具的一部分:PuTTY 下载页面
I want to build and run a command like this to copy sample.txt to my home directory on the remote machine:
我想构建并运行这样的命令将 sample.txt 复制到远程机器上的主目录:
"C:\Program Files\PuTTY\pscp.exe" -sftp -l hans -pw changeme C:\Access\sample.txt 192.168.1.6:/home/hans/
So this procedure will build and run that command string.
因此,此过程将构建并运行该命令字符串。
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
You may prefer ShellAndWaitinstead of Shell, as David Fenton suggested in a comment on the previous answer.
您可能更喜欢ShellAndWait而不是 Shell,正如 David Fenton 在对上一个答案的评论中所建议的那样。
回答by Eugene Mayevski 'Callback
You would need some SFTP ActiveX Control that works in Access. I know that our SFTP controlis used by some customers in VBA and in Access in particular.
您需要一些适用于 Access 的 SFTP ActiveX 控件。我知道我们的 SFTP 控件被一些客户在 VBA 中使用,特别是在 Access 中。
回答by Raj More
I have done it the following way in Access 97:
我在 Access 97 中按以下方式完成了:
- Buy a SFTP client that has an OCX that is available to MS Access
- Write VBA code to use the SFTP control
- 购买具有可用于 MS Access 的 OCX 的 SFTP 客户端
- 编写 VBA 代码以使用 SFTP 控件
In one particular case, there was no OCX - only executable - we had to do a batch file for that one.
在一种特殊情况下,没有 OCX——只有可执行文件——我们不得不为那个文件做一个批处理文件。

