Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Guest

Re: Fail to Connect SFTP

martin wrote:

You have to set TunnelHostKey too:
https://winscp.net/eng/docs/rawsettings#tunnelhostkey


It works!
I have add this code as your suggest
  sessionOptions.AddRawSettings("TunnelHostKey", "ssh-rsa 1024 xxx")


thank you so much for your help
tun.tuang31

Fail to Connect SFTP

Hello,

Connecting using winscp it self is OK, but i got a problem whent connecting to SFTP using winscp Library.
Below is the error i got when try to connect
Expected host key was not configured, use -hostkey switch.
Host key fingerprint is xxxx.
Authentication failed.

And this is my code, i got this using menu "Session>>Generate Session URL/code"
' Set up session options

        Dim sessionOptions As New SessionOptions
        With sessionOptions
            .Protocol = Protocol.Sftp
            .HostName = "xxx.net"
            .UserName = "username"
            .Password = "password"
            .SshHostKeyFingerprint = "ssh-rsa 1024 xxx"
        End With

        sessionOptions.AddRawSettings("Tunnel", "1")
        sessionOptions.AddRawSettings("TunnelHostName", "255.255.255.255")
        sessionOptions.AddRawSettings("TunnelUserName", "user")
        sessionOptions.AddRawSettings("TunnelPublicKeyFile", "C:%5CUsers%5CAdministrator%5CDesktop%5CFile.ppk")

        Using session As New Session
            ' Connect
            session.Open(sessionOptions)

            ' Your code
        End Using


Please advice how to fix this,

Thank you