1

I'm using below code snippet to connect to a server using wininet.dll in VBA but not able to connect to that. But when I try to connect to the server using WinSCP 5.15.1, it's able to connect. And when I try to use 5.5.5.0 version of WinSCP, it shows error "Couldn't agree a key exchange algorithm". It also shows login error when I try to connect it using ftp command in cmd.

I'm wondering is it possible to connect to the server using wininet.dll in VBA by fixing any thing.

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
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Abhinav Kushagra
  • 176
  • 1
  • 2
  • 15

1 Answers1

2

If you get "Couldn't agree a key exchange algorithm" in WinSCP, it means that you are using SFTP protocol, not FTP. Wininet speaks FTP only, not SFTP.

You will have to use SFTP library. See SFTP upload in VBA.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I only need to check whether a particular path exists. Could you please suggest me the best way to check in VBA? – Abhinav Kushagra Apr 15 '20 at 14:22
  • I have answered your question about *"Not able to connect using “wininet.dll” in VBA"*. If you have a new problem now, please post a new question. – Martin Prikryl Apr 15 '20 at 16:07