我使用 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 使用“xxxx”主机格式而不是 xxxx,但这对我没有帮助。
变量的值为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]
任何帮助将不胜感激。