SSH.NET "Server string is null or empty" 异常

SSH.NET "Server string is null or empty" exception

我使用SSH.NET(2013.4.7版本)库上传文件到SFTP服务器。 这是我的一段代码:

using (var client = new SftpClient(host, port, username, password))
{
    client.Connect();
    ...
}

我在执行 Connect() 方法时收到以下错误消息: "System.InvalidOperationException: Server string is null or empty."

我在这里找到了关于这个问题的小建议:http://www.ipbalance.com/programming/ms-powershell/1098-powershell-how-to-use-sshnet-library-for-cisco-on-windows-7.html 使用 'x.x.x.x' 主机格式而不是 x.x.x.x,但这对我没有帮助。

host 变量的值为“153.112.49.198”。 port 是 22。 当我使用具有相同主机、端口、用户名和密码的 FileZilla 工具时,它工作正常。

堆栈跟踪:

System.InvalidOperationException: Server string is null or empty.
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at [here is my method]

我们将不胜感激。

终于,我解决了这个问题。 默认情况下,SFTP 服务器将“最大连接数”设置为值“1”,因此我无法连接,因为 FileZilla 的连接已经创建。