我正在尝试使用以下代码建立与SFTP服务器的连接,我会收到此错误消息“未验证主机密钥!” 。
SessionOptions so = new SessionOptions {
Protocol = Protocol.Sftp,
HostName = "xx.xx.xx.xx",
UserName = "usera",
Password = "user123",
SshHostKeyFingerprint = "2048 78:1d:67:f9:89:f5:ea:8e:28:84:68:04:f6:50:e7:ea"
};
using (Session s = new Session())
{
s.Open(so);
}
但是,如果我使用以下代码建立连接,则可以连接。
System.Diagnostics.Process winscp = new System.Diagnostics.Process();
winscp.StartInfo.FileName = "winscp.com";
winscp.StartInfo.UseShellExecute = false;
winscp.StartInfo.CreateNoWindow = true;
winscp.StartInfo.RedirectStandardOutput = true;
winscp.StartInfo.RedirectStandardInput = true;
winscp.Start();
winscp.StandardInput.WriteLine("open sftp://usera:[email protected]");
winscp.StandardInput.Close();
我很想知道第一种方法做错了什么?
您的主机密钥指纹格式错误。您至少缺少键类型(ssh-rsa
或ssh-dss
)。
请参阅WinSCP常见问题解答。在哪里可以获取SSH主机密钥指纹来授权服务器?
使用脚本的代码成功,因为您已经缓存了指纹。.NET程序集从不使用指纹缓存。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句