连接到 FTP 端口 21 时,SSH.NET 出现“套接字读取操作已超时”异常

Pin*_*ong 3 .net c# ftp sftp ssh.net

当客户端尝试连接到 FTP 服务器时,我收到以下异常:

套接字读取操作在 30000 毫秒后超时。

Source = "Renci.SshNet"

在 Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket socket, Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) at Renci.SshNet.Session.SocketReadLine(TimeSpan timeout) at Renci.SshNet.Session.Connect()在 Renci.SshNet.BaseClient.Connect() 在 SftpClient.ReadAllBytesAsync() 在 C:\SftpClient\SftpClient.cs:line 42

代码如下:

using (Renci.SshNet.SftpClient sftp = new Renci.SshNet.SftpClient(server,
                                                    21,
                                                    Username,
                                                    Password))                      
    sftp.Connect();  //exception here
    content = sftp.ReadAllBytes(FilePath);    
    sftp.Disconnect();                      
}
Run Code Online (Sandbox Code Playgroud)

SSH.NET 版本:2016.1.0

但是,它通过 telnet 连接,如下所示通过命令提示符:

using (Renci.SshNet.SftpClient sftp = new Renci.SshNet.SftpClient(server,
                                                    21,
                                                    Username,
                                                    Password))                      
    sftp.Connect();  //exception here
    content = sftp.ReadAllBytes(FilePath);    
    sftp.Disconnect();                      
}
Run Code Online (Sandbox Code Playgroud)

服务器端的工作人员向我发送了我在 Windows 10 上安装的公共证书。

任何的想法?


解决方案:

使用这个:github.com/robinrodricks/FluentFTP

Mar*_*ryl 5

SSH.NET 是 SSH/SFTP 客户端(端口 22)。

您不能使用它连接到 FTP 服务器(端口 21)。FTP 和 SFTP 是两种完全不同的协议。

对于 FTP,您可以使用: