与SSH.NET连接到OpenSSH 7.4p1失败,并显示“服务器响应在位置包含空字符".但可以在WinSCP中使用 [英] Connecting with SSH.NET to OpenSSH 7.4p1 fails with "The server response contains a null character at position" but works in WinSCP

查看:62
本文介绍了与SSH.NET连接到OpenSSH 7.4p1失败,并显示“服务器响应在位置包含空字符".但可以在WinSCP中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SSH.NET(2020.0.0)连接到SFTP服务器.

我的代码看起来像这样简单:

  try{var x = new ConnectionInfo(FtpIpAddress,22,FtpUser,新的PasswordAuthenticationMethod(FtpUser,FtpPw));使用(var sftpClient = new SftpClient(x)){sftpClient.Connect();sftpClient.Disconnect();}}捕获(异常e){Console.WriteLine(e.Message);} 

但是当我运行代码时,出现以下错误:

 服务器响应在位置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 ..协议版本交换完成之前,服务器不得发送空字符. 

我不知道如何解决它,手动使用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中修复.似乎他们甚至都没有考虑过这个错误,因为更改未包含在 7.5发行说明中.

您已经发现自己,SSH.NET 2016.1.0也仅对LF感到满意.


一个完全不同的问题,可能导致相同的错误消息:服务器响应包含空字符"使用SSH.NET 连接到端口990上的FTP站点时.

I am trying to connect to an SFTP server using SSH.NET (2020.0.0).

My code looks as simple as this:

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);
}

But when I run the code, I get following error:

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.

I have no clue how to solve it, when using WinSCP manually it works fine, when using WinSCP.NET, it works fine as well with code. But I can not use WinSCP.NET on a Linux distribution.

So anyone got an idea what's wrong?

解决方案

The SSH.NET (2020.0.0) expects that the SSH server version string ends with CRLF (0D0A) sequence.

Your server seems to send only LF (0A).

WinSCP is more tolerant – It's happy with the LF.

Checking the OpenSSH source code, it seems that OpenSSH 7.4p1 (only that specific version) is sending the LF only. Older versions did not have this problem. And it was fixed in OpenSSH 7.5. It seems that they didn't not even consider this a bug, as the change was not included in 7.5 release notes.

As you have found out yourself, SSH.NET 2016.1.0 is also happy with the LF only.


A completely different problem that can lead to the same error message: "The server response contains a null character" when connecting to FTP site on port 990 using SSH.NET.

这篇关于与SSH.NET连接到OpenSSH 7.4p1失败,并显示“服务器响应在位置包含空字符".但可以在WinSCP中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆