如何解决SSH.NET中的“错误数据包长度"错误? [英] How to resolve a 'Bad packet length' error in SSH.NET?
问题描述
我正在尝试使用 SSH.NET 通过SFTP上传文件. SFTPClient.Connect()
引发SshConnectionException,并显示消息错误的数据包长度1302334341".这是我的代码:
I'm trying to upload files via SFTP, using SSH.NET. SFTPClient.Connect()
throws an SshConnectionException with the message, "Bad packet length 1302334341." This is my code:
static void Main()
{
try
{
SftpClient sftp = new SftpClient(server, 22, userID, password);
sftp.Connect();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
我在另一个讨论中看到,这可能与加密有关.我正在使用AES,并且我有一个主机密钥.不过,我不知道如何输入加密.根据讨论,我正在玩这个游戏:
I saw in another discussion that this probably has to do with encryption. I'm using AES, and I have a host key. I don't understand how to enter the encryption, though. Based on that discussion, I was playing with this:
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()的参数不是正确的,但是我对使用此库有些迷惑;您能帮我弄清楚如何正确设置加密(假设是问题所在)吗?
I know that's not the right set of arguments to pass to Encryptions.Add(), but I'm a little lost with using this library; can you help me figure out how to set the encryption properly (assuming that's the problem)?
推荐答案
已解决,已在此讨论中.我需要使用
Solved, in this discussion. I needed to remove encryptions using
foreach (var d in connectionInfo.Encryptions.Where(p => p.Key != "aes128-cbc").ToList())
{
connectionInfo.Encryptions.Remove(d.Key);
}
用我打算使用的加密方式代替
substituting in whichever encryption I intend to use
这篇关于如何解决SSH.NET中的“错误数据包长度"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!