【问题标题】:Not able to connect to FTP server using "wininet.dll" in VBA but can connect with WinSCP无法在 VBA 中使用“wininet.dll”连接到 FTP 服务器,但可以使用 WinSCP 连接
【发布时间】:2020-07-27 11:13:48
【问题描述】:

我正在使用下面的代码 sn-p 在 VBA 中使用wininet.dll 连接到服务器,但无法连接到该服务器。但是当我尝试使用 WinSCP 5.15.1 连接到服务器时,它能够连接。当我尝试使用 5.5.5.0 版本的 WinSCP 时,它显示错误 “无法同意密钥交换算法”。 当我尝试在cmd 中使用ftp 命令连接它时,它也会显示登录错误。

我想知道是否可以通过修复任何东西在 VBA 中使用wininet.dll 连接到服务器。

Public Function checkFTPpath(ByVal ServerName, ByVal Username, ByVal password, ByVal remote_path) As Boolean

  Dim hostFile As String
  Dim INet As Long
  Dim INetConn As Long
  Dim RetVal As Long
  Dim Success As Boolean

  Success = False
  RetVal = False
  INet = InternetOpen("MyFTP Control", 1&, vbNullString, vbNullString, 0&)
  If INet > 0 Then
    INetConn = InternetConnect(INet, ServerName, 21, Username, password, 1&, 0&, 0&)
      If INetConn > 0 Then
          Success = FtpSetCurrentDirectory(INetConn, "/")
          Success = FtpSetCurrentDirectory(INetConn, remote_path)
        RetVal = InternetCloseHandle(INetConn)
      End If
      RetVal = InternetCloseHandle(INet)
  End If
  checkFTPpath = Success

End Function

【问题讨论】:

    标签: excel vba ftp winscp wininet


    【解决方案1】:

    如果您在 WinSCP 中得到“无法同意密钥交换算法”,则表示您使用的是 SFTP 协议,而不是 FTP。 Wininet 只支持 FTP,不支持 SFTP。

    您必须使用 SFTP 库。见SFTP upload in VBA

    【讨论】:

    • 我只需要检查特定路径是否存在。您能否建议我检查 VBA 的最佳方法?
    • 我已经回答了您关于“无法在 VBA 中使用“wininet.dll”进行连接”的问题。如果您现在有新问题,请发布新问题。
    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2023-03-14
    • 2011-09-26
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多