SSH.NET - 消息类型 80 无效
SSH.NET - Message type 80 is not valid
我有以下代码尝试连接到使用 OpenSSH 构建的 SFTP 服务器(该服务器工作正常,因为我已经能够通过 WinSCP 成功连接到此 FTP客户):
ConnectionInfo ConnNfo = new ConnectionInfo("127.0.0.1", 22, "usertest",
new AuthenticationMethod[]{
// Pasword based Authentication
new PasswordAuthenticationMethod("usertest","usertest"),
}
);
// Upload A File
using (var sftp = new SftpClient(ConnNfo))
{
sftp.Connect();
sftp.ChangeDirectory(@"/C:/IISFTP/");
using (var uplfileStream = File.OpenRead(uploadfn))
{
sftp.UploadFile(uplfileStream, uploadfn, true);
}
sftp.Disconnect();
}
调用 sftp.Connect()
行时,引发以下异常:
Message type 80 is not valid
为什么会这样?如何使用 SSH.NET 连接到我的 SFTP 服务器?
谢谢
消息80代表SSH_MSG_GLOBAL_REQUEST
。
现代版本的 OpenSSH 服务器将此通用消息用于各种 proprietary extensions of the SSH protocol。
大多数客户端will/should 默默地忽略无法识别的消息。 SSH.NET 也确实忽略了 SSH_MSG_GLOBAL_REQUEST
,但在身份验证完成之前它不会收到消息。
不幸的是,OpenSSH 似乎甚至在身份验证之前就发送了其中一些(可能是 hostkeys-prove-00@openssh.com
)。
问题已在 SSH.NET 2016.0.0-beta1. See Issue #8 and Commit a1f46d4 中修复。
在旧版本中,转到 Session.cs
并在 Session.Connect()
方法中将下面的行向上移动到身份验证代码上方:
RegisterMessage("SSH_MSG_GLOBAL_REQUEST");
我会把它放在这一行下面:
RegisterMessage("SSH_MSG_USERAUTH_BANNER");
我有以下代码尝试连接到使用 OpenSSH 构建的 SFTP 服务器(该服务器工作正常,因为我已经能够通过 WinSCP 成功连接到此 FTP客户):
ConnectionInfo ConnNfo = new ConnectionInfo("127.0.0.1", 22, "usertest",
new AuthenticationMethod[]{
// Pasword based Authentication
new PasswordAuthenticationMethod("usertest","usertest"),
}
);
// Upload A File
using (var sftp = new SftpClient(ConnNfo))
{
sftp.Connect();
sftp.ChangeDirectory(@"/C:/IISFTP/");
using (var uplfileStream = File.OpenRead(uploadfn))
{
sftp.UploadFile(uplfileStream, uploadfn, true);
}
sftp.Disconnect();
}
调用 sftp.Connect()
行时,引发以下异常:
Message type 80 is not valid
为什么会这样?如何使用 SSH.NET 连接到我的 SFTP 服务器?
谢谢
消息80代表SSH_MSG_GLOBAL_REQUEST
。
现代版本的 OpenSSH 服务器将此通用消息用于各种 proprietary extensions of the SSH protocol。
大多数客户端will/should 默默地忽略无法识别的消息。 SSH.NET 也确实忽略了 SSH_MSG_GLOBAL_REQUEST
,但在身份验证完成之前它不会收到消息。
不幸的是,OpenSSH 似乎甚至在身份验证之前就发送了其中一些(可能是 hostkeys-prove-00@openssh.com
)。
问题已在 SSH.NET 2016.0.0-beta1. See Issue #8 and Commit a1f46d4 中修复。
在旧版本中,转到 Session.cs
并在 Session.Connect()
方法中将下面的行向上移动到身份验证代码上方:
RegisterMessage("SSH_MSG_GLOBAL_REQUEST");
我会把它放在这一行下面:
RegisterMessage("SSH_MSG_USERAUTH_BANNER");