【问题标题】:"The server response contains a null character" when connecting to FTP site on port 990 using SSH.NET使用 SSH.NET 连接到端口 990 上的 FTP 站点时,“服务器响应包含一个空字符”
【发布时间】:2021-04-22 04:18:48
【问题描述】:

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

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

我对来自here 的文档的看法是,这个问题似乎是一个预期错误。我已阅读https://www.rfc-editor.org/rfc/rfc4253#section-4.2 上的文档建议的信息,并且我“认为”我理解这意味着我尝试连接的主机可能未正确配置。我的问题是,由于我无法更改主机的配置方式,是否有办法通过 SSH.NET 库解决此错误,或者我只是在使用 SSH.NET 时处于死胡同?

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

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

这是主机信息(来自 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

【问题讨论】:

    标签: c# ssl ftp sftp ssh.net


    【解决方案1】:

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

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

    因为您将不得不使用第 3 方库。见Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?


    尽管大多数 FTP 服务器都支持标准的显式 FTPS(通过端口 21)。如果您的服务器有,请使用它,而不是旧端口 990。请参阅FTPS (FTP over SSL) in C#

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


    另见Difference between FTP/FTPS/SFTP - Configurable connection to any of them


    可能导致相同错误消息的完全不同的问题:Connecting with SSH.NET to OpenSSH 7.4p1 fails with "The server response contains a null character at position" but works in WinSCP

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 1970-01-01
      • 2021-04-22
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多