2012-06-04 83 views
5

我試圖通過SFTP上傳文件,使用SSH.NETSFTPClient.Connect()用消息「Bad packet length 1302334341」拋出SshConnectionException。這是我的代碼:如何解決SSH.NET中'錯誤的數據包長度'錯誤?

static void Main() 
{ 
try 
{ 
SftpClient sftp = new SftpClient(server, 22, userID, password); 
sftp.Connect(); 
} 
catch(Exception e) 
{ 
Console.WriteLine(e.Message); 
} 
} 

我在另一個discussion,這可能與加密該怎麼辦看到。我使用AES,而且我有一個主機密鑰。不過,我不明白如何輸入加密。在此基礎上討論,我玩這個:

ConnectionInfo connectionInfo = new PasswordConnectionInfo(server, 22, userID, password); 
connectionInfo.Encryptions.Clear(); 
connectionInfo.Encryptions.Add("aes","ssh-rsa 2048 11:22:34:d4:56:d6:78:90:01:22:6b:46:34:54:55:8a") 

我知道這不是正確的一組參數傳遞給Encryptions.Add(),但我有點用這個庫丟失;你能幫我弄清楚如何正確設置加密(假設這是問題)?

+3

解決,在[這個討論](http://sshnet.codeplex.com/discussions/358307)。我需要使用'foreach(var in connectionInfo.Encryptions.Where(p => p.Key!=「aes128-cbc」)去除加密)ToList()) { connectionInfo.Encryptions.Remove(d.Key) ; }',替換我打算使用的任何加密。 – sigil

+0

你可以把你的評論作爲答案 - 也幫助我! – andreister

回答

0

解決,在this discussion。我需要使用

foreach (var d in connectionInfo.Encryptions.Where(p => p.Key != "aes128-cbc").ToList()) 
{ 
connectionInfo.Encryptions.Remove(d.Key); 
} 

代中除去加密取其加密我打算使用