【发布时间】:2019-02-11 21:00:53
【问题描述】:
请参阅下面的代码,这是从另一个站点提取的,我用我的详细信息进行了修改。我正在尝试根据触发事件自动上传到我的 SFTP 站点。由于某种原因,它不起作用。如果我所做的有任何问题,请告诉我。下面是即时窗口中的代码调试器。
Private Sub Form_Close()
Const CMD_WINSCP As String = _
"WinSCP.com /Command ""open sftp://user:password@server/ -hostkey=""""fingerprint"""""" ""put local remote"" ""exit"""""
Dim User As String
Dim Password As String
Dim Fingerprint As String
Dim LocalFile As String
Dim RemotePath As String
Dim Command As String
Dim Server As String
'TODO: Initialize parameters.
User = "Inarion"
Password = "pwd123"
Fingerprint = "CopiedFromGenerateSessionURLCodeSSHHostKey"
LocalFile = "c:\users\myname\path\filename.csv"
RemotePath = "stackoverflow.com/users/path/"
Server = "999.999.999.999.sftp.stackoverflow.com" ' IPv4 should work as well
Command = CMD_WINSCP
Command = Replace(Command, "user", User)
Command = Replace(Command, "password", Password)
Command = Replace(Command, "fingerprint", Fingerprint)
Command = Replace(Command, "local", LocalFile)
Command = Replace(Command, "remote", RemotePath)
Command = Replace(Command, "server", Server)
Debug.Print Command
Shell Command
from Immediate window:
WinSCP.com /Command "open sftp://Inarion:pwd123@999.999.999.999.sftp.stackoverflow.com/ -hostkey=""CopiedFromGenerateSessionURLCodeSSHHostKey""" "put c:\users\myname\path\filename.csv sftp.stackoverflow.com/users/path/" "exit""
【问题讨论】:
-
你有什么问题?
-
我更新了我的帖子以更好地反映我不知道为什么它不工作并且希望这里有人这样做。谢谢。
-
您如何确保 VBA 代码可以找到
winscp.com?PATH有吗?如果不是,请改用winscp.com的完整路径,如Using VBA to run WinSCP script 中所示。 -
要连接到您的服务器,我认为您要么使用 sftp 地址或 IP 地址。我无法想象这种组合会起作用。您是否有其他方法可以验证您使用的地址是否正确? (考虑在浏览器中输入它,或通过命令窗口
Ping-ing 它。)只要该地址仍然无法访问,您的脚本将无法运行......