我正在尝试使用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。
有人知道怎么回事吗?
发布于 2021-01-18 11:08:09
SSH.NET (2020.0.0)期望SSH服务器版本字符串以CRLF (0D0A
)序列结尾。
您的服务器似乎只发送LF (0A
)。
WinSCP更宽容--它对LF很满意。
检查OpenSSH源代码,似乎OpenSSH 7.4p1 (只有特定版本)只发送LF。旧版本没有这个问题。并在OpenSSH 7.5中固定。似乎他们甚至不认为这是一个错误,因为变化没有包括在7.5发行说明中。
正如你自己发现的那样,SSH.NET 2016.1.0也只对LF感到满意。
SSH.NET 2020.0.1是专门用于解决本期问题的。
一个完全不同的问题可能导致相同的错误消息:https://stackoverflow.com/q/65764847/850848。
https://stackoverflow.com/questions/65777501
复制相似问题