SSH.NET“服务器字符串为空或空”异常

时间:2016-08-04 15:36:02

标签: c# .net sftp ssh.net

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

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

我在Connect()方法执行时收到以下错误消息: “System.InvalidOperationException:服务器字符串为空或空。”

我在这里找到了关于这个问题的小建议: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]

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:6)

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