【发布时间】: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
【问题讨论】: