I am trying to connect up to a WinSCP server using the WinSCP .NET assembly. The problem I am having is that it bombs checking the host key fingerprint. I have created a RSA key. My code is as follows:
var server = new WinSCP.SessionOptions();
server.UserName = "ftp_user";
server.Password = "******";
server.HostName = "192.x.x.x";
server.Protocol = WinSCP.Protocol.Sftp;
server.SshHostKeyFingerprint =
"9f:39:52:d5:08:0c:1d:a8:02:c9:7e:44:49:7f:44:fb";
var session = new WinSCP.Session();
session.Open(server);
At the SshHostKeyFingerprint
property assignment I get the following error:
SSH host key fingerprint "9f:39:52:d5:08:0c:1d:a8:02:c9:7e:44:49:7f:44:fb" does not match pattern /(ssh-rsa |ssh-dss )?\d+ ([0-9a-f]{2}:){15}[0-9a-f]{2}(;(ssh-rsa |ssh-dss )?\d+ ([0-9a-f]{2}:){15}[0-9a-f]{2})*/
If I am reading this right it is checking for 15 2 character sets, and I am assigning a 16 set value. I got this value from the server.
UPDATE:
What I was missing was the fingerprint type (ssh-dss
or ssh-rsa
) and its size (1024
, 2048
etc.). Therefore, the answer is as follows:
server.SshHostKeyFingerprint =
"ssh-rsa 1024 9f:39:52:d5:08:0c:1d:a8:02:c9:7e:44:49:7f:44:fb";
If I am reading the regular expression correctly it does not give you any idea that you need the fingerprint size after the fingerprint type.
I hope this helps someone else. Thanks everyone for your insight and input.