【问题标题】:"Host key wasn't verified!" when connecting using WinSCP .NET assembly“主机密钥未验证!”使用 WinSCP .NET 程序集连接时
【发布时间】:2014-07-04 08:30:40
【问题描述】:

我正在尝试使用以下代码与 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();

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

【问题讨论】:

    标签: public-key winscp winscp-net


    【解决方案1】:

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

    请参阅 WinSCP 常见问题解答Where do I get SSH host key fingerprint to authorize the server?


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

    最新版本的 WinSCP issue a more meaningful message when the fingerprint is not matched

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-08
      • 2020-07-15
      • 2014-01-14
      • 2016-12-20
      • 2019-12-03
      • 2014-04-03
      相关资源
      最近更新 更多