SSH.NET”;服务器字符串为null或为空“;例外

本文关键字:例外 null 字符串 NET 服务器 SSH | 更新日期: 2023-09-27 18:00:16

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

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

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

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

任何帮助都将不胜感激。

SSH.NET”;服务器字符串为null或为空“;例外

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