我正在尝试使用 SSH.NET (2020.0.0) 连接到 SFTP 服务器。
我的代码看起来很简单:
try
{
var x = new ConnectionInfo(FtpIpAddress, 22, FtpUser,
new PasswordAuthenticationMethod(FtpUser, FtpPw));
using (var sftpClient = new SftpClient(x))
{
sftpClient.Connect();
sftpClient.Disconnect();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
但是当我运行代码时,出现以下错误:
The server response contains a null character at position 0x00000028:
00000000 53 53 48 2D 32 2E 30 2D 4F 70 65 6E 53 53 48 5F SSH-2.0-OpenSSH_
00000010 37 2E 34 70 31 20 44 65 62 69 61 6E 2D 31 30 2B 7.4p1 Debian-10+
00000020 64 65 62 39 75 32 0A 00 deb9u2..
A server must not send a null character before the Protocol Version Exchange is complete.
我不知道如何解决它,当手动使用 WinSCP 时,它工作正常,当使用 WinSCP.NET 时,它与代码一起工作也很好。但我无法在 Linux 发行版上使用 WinSCP.NET。
那么有人知道出了什么问题吗?
SSH.NET (2020.0.0) 期望 SSH 服务器版本字符串以 CRLF 结尾(0D0A
) 顺序。
您的服务器似乎只发送 LF (0A
).
WinSCP 更加宽容——它对 LF 很满意。
检查 OpenSSH 源代码,似乎 OpenSSH 7.4p1(仅限该特定版本)仅发送 LF。旧版本没有这个问题。 OpenSSH 7.5 中已修复该问题。看来他们甚至不认为这是一个错误,因为change https://github.com/openssh/openssh-portable/commit/5b90709ab8704dafdb31e5651073b259d98352bc没有被包含在7.5 发行说明 https://www.openssh.com/txt/release-7.5.
正如您自己发现的那样,SSH.NET 2016.1.0 也仅对 LF 感到满意。
SSH.NET 2020.0.1 专门发布用于解决这个问题 https://github.com/sshnet/SSH.NET/issues/761.
可能导致相同错误消息的完全不同的问题:使用 SSH.NET 连接到端口 990 上的 FTP 站点时,“服务器响应包含空字符” https://stackoverflow.com/q/65764847/850848.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)