使用VBA和WINSCP从MS-Access上传SFTP [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

请看下面的代码,这是从另一个网站上提取的,我修改了我的详细信息。我正在尝试根据触发事件自动上传到我的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:[email protected]/ -hostkey=""CopiedFromGenerateSessionURLCodeSSHHostKey""" "put c:\users\myname\path\filename.csv sftp.stackoverflow.com/users/path/" "exit""
vba ms-access sftp winscp
1个回答
0
投票

所以你似乎特意询问了连接字符串。我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:[email protected]/作为命令字符串的第一部分。

© www.soinside.com 2019 - 2024. All rights reserved.