1

我正在尝试使用以下代码建立与 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:user123@xx.xx.xx.xx");
winscp.StandardInput.Close();

我很想知道我在第一种方法中做错了什么?

4

1 回答 1

4

您的主机密钥指纹格式错误。您至少缺少一个键类型(ssh-rsa或)。ssh-dss

请参阅 WinSCP 常见问题解答我在哪里获取 SSH 主机密钥指纹以授权服务器?


您使用脚本的代码成功,因为您缓存了指纹。.NET 程序集从不使用指纹缓存。

当指纹不匹配时,最新版本的 WinSCP 会发出更有意义的消息

于 2014-07-06T18:44:34.023 回答