2016-08-04 70 views
1

我使用SSH.NET(2013.4.7版本)庫將文件上傳到SFTP服務器。 這是一段我的代碼:SSH.NET「服務器字符串爲空或空」異常

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] 

任何幫助將不勝感激。

+0

你調試過嗎? '主機'的內容是什麼? –

+0

@RenéVogt,編輯問題 –

+0

您可以使用命令行'ssh'或PuTTY連接嗎?其他變量是什麼? – Jakuje

回答

4

最後,我已經解決了這個問題。 默認情況下,SFTP服務器的設置「最大連接數」設置爲「1」,所以我無法連接,因爲FileZilla的連接已經創建。

相關問題