无法在VBA中使用“ wininet.dll”连接到FTP服务器,但可以与WinSCP连接

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

我正在使用下面的代码段通过VBA中的“ wininet.dll”连接到服务器,但无法连接到该服务器。但是,当我尝试使用WinSCP 5.15.1连接到服务器时,它就可以连接。并且当我尝试使用WinScp 5.5.5.0版本时,它显示错误“不同意密钥交换算法”。当我尝试使用ftp中的cmd命令连接它时,它还会显示登录错误。

我想知道是否有可能通过修复任何问题使用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个回答
2
投票
“无法同意密钥交换算法”]],则表示您正在使用SFTP协议,而不是FTP。 Wininet

speaks仅FTP,而不是SFTP。您将必须使用SFTP库。参见SFTP upload in VBA

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