【问题标题】:SFTP Upload from MS-Access using VBA and WINSCP [duplicate]使用 VBA 和 WINSCP 从 MS-Access 上传 SFTP [重复]
【发布时间】: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.comPATH 有吗?如果不是,请改用winscp.com 的完整路径,如Using VBA to run WinSCP script 中所示。
  • 要连接到您的服务器,我认为您要么使用 sftp 地址 IP 地址。我无法想象这种组合会起作用。您是否有其他方法可以验证您使用的地址是否正确? (考虑在浏览器中输入它,或通过命令窗口Ping-ing 它。)只要该地址仍然无法访问,您的脚本将无法运行......

标签: vba ms-access sftp winscp


【解决方案1】:

看来您是在专门询问连接字符串。我 99% 确定你所拥有的那个是不正确的。您需要将服务器(IP)地址放在那里(而不仅仅是在远程文件夹中)。特别是因为密码分配状态为ActualSFTPPassword,butNo@orDomain

我无法确定您的连接字符串来自何处,但假设您是从 official documentation 获得的,我无法识别语法错误。

请将以下三行添加到您的代码中(在适当的位置):

Dim Server as String
Server = "yourTargetDomain.com" ' IPv4 should work as well
Command = Replace(Command, "server", Server)

然后再试一次。

示例:从sftp://user:password@server/ 开始,用户名Inarion 和虚构密码pwd123 和目标域Stackoverflow.com,您将得到sftp://inarion:pwd123@Stackoverflow.com/ 作为命令字符串的第一部分。

【讨论】:

  • 更新了上面的代码-如果我误解了-请告诉我-仍然无法正常工作-在我的即时窗口中来自 FROM spot 和 TO spot 的消息仅由空格分隔,这很奇怪吗?我原以为会有某种其他指标(即“或,或/)
  • @bobby 我不会认为以空格分隔的参数不寻常。在这种环境中,包含空格的参数将(必须)用引号括起来。
猜你喜欢
  • 1970-01-01
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-24
  • 1970-01-01
  • 2017-12-25
  • 1970-01-01
相关资源
最近更新 更多