SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.SshHostKeyFingerprint is not set

When connecting using SFTP or SCP protocols, which run over SSH, server’s host key must be verified. In WinSCP .NET assembly, you do by setting SessionOptions.SshHostKeyFingerprint property to the value of fingerprint of the expected host key.

A C# example:

SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "example.com",
    UserName = "username",
    Password = "password",
    SshHostKeyFingerprint = "ssh-rsa 2048 2EPqmpSRaRtUIqwvm15rzavssrhHxJ3avJWh9mBaz8M=",
};

To learn how to find the value of the fingerprint see Where do I get SSH host key fingerprint to authorize the server?

Though as with the most of session settings, if you have the site set up in WinSCP GUI, you can have it generate a code template for you, including the SessionOptions.SshHostKeyFingerprint.

Last modified: by martin – Currently locked by: 173.44.216.27