“服务器响应包含空字符"使用SSH.NET连接到端口990上的FTP站点时 [英] "The server response contains a null character" when connecting to FTP site on port 990 using SSH.NET

查看:95
本文介绍了“服务器响应包含空字符"使用SSH.NET连接到端口990上的FTP站点时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Renci SSH.NET连接到FTP站点并从我的C#应用​​程序下载文件.我可以使用FileZilla和WinSCP(在Windows 10 Pro 64上)并通过HTTP连接(主机正在运行CrushFTP)成功连接到主机,但无法弄清楚如何使用 SSH.NET .我收到此错误:

服务器响应在位置0x00000004处包含空字符:00000000 15 03 03 00....在协议版本交换完成之前,服务器不得发送空字符.

我对此处中的文档的看法是,这个问题似乎是预期的错误.我已阅读 https://tools.ietf.org上的文档建议的信息./html/rfc4253#section-4.2 ,我认为"我了解这意味着我尝试连接的主机可能未正确配置.我的问题是,由于我没有能力更改主机的配置方式,因此SSH.NET库是否有解决此错误的方法,还是使用SSH.NET只是一个死胡同?

这是我的代码-试图简化到最低限度:

 使用系统;使用Renci.SshNet;命名空间mysftp{班级计划{静态void Main(string [] args){字符串host ="myftps.hostname.com";字符串用户名="myusername";字符串密码="securepassword";int端口= 990;字符串remoteFolder ="/";使用(SftpClient sftp =新的SftpClient(主机,端口,用户名,密码)){尝试{Console.WriteLine(尝试连接到" +主机+"..."));sftp.Connect();Console.WriteLine(sftp.ConnectionInfo.ServerVersion);sftp.Disconnect();}捕获(异常e){Console.WriteLine(e);扔;}}}}} 

这是主机信息(来自WinSCP的远程服务器信息):

 远程系统= UNIX类型:L8文件传输协议= FTP加密协议= TLS/SSL隐式加密,TLSv1.2加密算法= TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384、2048位RSA,ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx = ECDH Au = RSA Enc = AESGCM(256)Mac = AEAD压缩=否------------------------------------------------------------证书指纹<<编辑的指纹信息>>------------------------------------------------------------可以更改权限=是可以更改所有者/组=否可以执行任意命令=仅协议命令可以创建符号/硬链接=否/否可以查找用户组=​​否可以复制远程文件=否可以检查可用空间=否可以计算文件校验和=是本地文本(ASCII)模式传输=否------------------------------------------------------------附加信息服务器支持以下FTP附加功能:认证TLS身份验证SSL卫星电视网PBSZ保护CCC克朗特电动汽车紧急审查小组MDTMMDTM YYYYMMDDHHMMSS [+-TZ];文件名MFMT尺寸休息流模式Z清单-Q现场时间网站MD5XMD5网站MD5现场随机存取MLST Type *; Size *; Modify *; Perm *; UNIX.owner *; UNIX.group *;UTF8 

解决方案

端口990用于基于隐式加密TLS/SSL连接(又称为隐式FTPS)的FTP协议.而SSH.NET是SSH/SFTP库.FTPS和SFTP是完全不同的东西.您不能将SSH.NET用于FTPS.

隐式FTPS已过时.并非所有的FTP(S)库都支持它.值得注意的是,内置的.NET FTP实现 FtpWebRequest 不支持.

因为您将不得不使用第三方库.请参见 .NET FtpWebRequest是否支持隐式(FTPS)和显式(FTPES)?


尽管大多数FTP服务器确实支持标准的显式FTPS(通过端口21).如果您的服务器支持,请使用它,而不要使用旧版端口990.请参见 C#中的FTPS(基于SSL的FTP)

如果没有,请与服务器管理员联系以启用它.


另请参见 FTP/FTPS/SFTP之间的区别-与它们中的任何一个的可配置连接


一个完全不同的问题,可能导致相同的错误消息:使用SSH.NET连接到OpenSSH 7.4p1失败,服务器响应在位置处包含空字符".但可以在WinSCP 中使用.

I'm trying to use Renci SSH.NET to connect to an FTP site and download files from my C# app. I can successfully connect to the host with FileZilla and WinSCP (on Windows 10 Pro 64), and through an HTTP connection (the host is running CrushFTP), but cannot figure out how to successfully connect from my C# app, using SSH.NET. I'm getting this error:

The server response contains a null character at position 0x00000004: 00000000 15 03 03 00....A server must not send a null character before the Protocol Version Exchange is complete.

My take on the documentation from here, is that this problem appears to be an expected error. I've read the information suggested by the documentation at https://tools.ietf.org/html/rfc4253#section-4.2 and I "think" I understand that to mean that the host that I'm trying to connect to may not be correctly configured. My question is, since I don't have the ability to change how the host is configured, whether there is a way around this error with the SSH.NET library or am I just at a dead end for using SSH.NET?

Here's my code - tried to simplify to bare minimum:

using System;
using Renci.SshNet;

namespace mysftp
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "myftps.hostname.com";
            string username = "myusername";
            string password = "securepassword";
            int port = 990;

            string remoteFolder = "/";

            using (SftpClient sftp = new SftpClient(host, port, username, password)) 
            {
                try
                {
                    Console.WriteLine("Attempting to connect to " + host + " ...");
                    sftp.Connect();
                    Console.WriteLine(sftp.ConnectionInfo.ServerVersion);
                    sftp.Disconnect();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
    }
}

Here is the host information (Remote server info from WinSCP):

Remote system = UNIX Type: L8
File transfer protocol = FTP
Cryptographic protocol = TLS/SSL Implicit encryption, TLSv1.2
Encryption algorithm = TLSv1.2: ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA, ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH     Au=RSA  Enc=AESGCM(256) Mac=AEAD

Compression = No
------------------------------------------------------------
Certificate fingerprint
<<fingerprint info redacted>>
------------------------------------------------------------
Can change permissions = Yes
Can change owner/group = No
Can execute arbitrary command = Protocol commands only
Can create symbolic/hard link = No/No
Can lookup user groups = No
Can duplicate remote files = No
Can check available space = No
Can calculate file checksum = Yes
Native text (ASCII) mode transfers = No
------------------------------------------------------------
Additional information
The server supports these FTP additional features:
  AUTH TLS
  AUTH SSL
  SSCN
  PBSZ
  PROT
  CCC
  CLNT
  EPSV
  EPRT
  MDTM
  MDTM YYYYMMDDHHMMSS[+-TZ];filename
  MFMT
  SIZE
  REST STREAM
  MODE Z
  LIST -Q
  SITE UTIME
  SITE MD5
  XMD5
  SITE MD5s
  SITE RANDOMACCESS
  MLST Type*;Size*;Modify*;Perm*;UNIX.owner*;UNIX.group*;
  UTF8

解决方案

Port 990 is used for FTP protocol over implicitly encrypted TLS/SSL connection (aka implicit FTPS). While SSH.NET is an SSH/SFTP library. FTPS and SFTP are completely different things. You cannot use SSH.NET for FTPS.

The implicit FTPS is obsolete thing. Not all FTP(S) libraries do support it. It's notable not supported by the built-in .NET FTP implementation, the FtpWebRequest.

For you will have to use a 3rd party library. See Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?


Though most FTP servers do support the standard explicit FTPS (over port 21). If your server does, use that, instead of the legacy port 990. See FTPS (FTP over SSL) in C#

If not, talk to the server administrator to enable it.


See also Difference between FTP/FTPS/SFTP - Configurable connection to any of them


A completely different problem that can lead to the same error message: Connecting with SSH.NET to OpenSSH 7.4p1 fails with "The server response contains a null character at position" but works in WinSCP.

这篇关于“服务器响应包含空字符"使用SSH.NET连接到端口990上的FTP站点时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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