ssh.net sftp 坏包长度/打开 SSH 版本 2 RSA? [英] ssh.net sftp Bad Packet length / open SSH version 2 RSA?

查看:66
本文介绍了ssh.net sftp 坏包长度/打开 SSH 版本 2 RSA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sftp 的新手,我正在尝试让 C# 程序通过 sftp 将文件发送到不在我控制之下的远程服务器.

I'm new to sftp and i'm trying to get a c# program to send a file via sftp to a remote server not under my control.

使用如下代码:

using (var sftp = new SftpClient(FTPAddress, FTPName, FTPPassword))
                    {
                        ConnectionInfo myCI = sftp.ConnectionInfo;

                        sftp.Connect(); // <<<< Exception on connect

                        sftp.UploadFile(sftp_ms, FileName,true);

                        sftp.Disconnect();
                    }

我收到数据包长度错误"异常.

I receive a "Bad packet length" exception.

Google 搜索显示错误的数据包长度可能是加密格式不匹配,但我不知道如何解决.

Google searching reveals that a bad packet length is likely to be a mismatch in encryption formats but I don't know how to resolve that.

我从客户那里收到的规格是:

The specification i've received from the client is:

Keys must be in Open SSH version 2 format RSA format

我不知道该怎么做.以前的 SO 问题 如何解决坏"SSH.NET 中的数据包长度错误? 有一个指向 sshnet.codeplex 讨论的链接,其中删除您不想要的加密密钥解决了该海报的问题.

I don't know how to do this. A previous SO question How to resolve a 'Bad packet length' error in SSH.NET? has a link to sshnet.codeplex discussion where removing the encryption keys that you don't want solved the issue for that poster.

我可以在 ssh.net 的 connectioninfo 类中看到 16 个条目,但没有一个声明开放 SSH 版本 2 RSA,尽管其中一个很可能是(我试过谷歌搜索).

I can see 16 entries in ssh.net's connectioninfo class but none of them state open SSH version 2 RSA though one of them may very well be (i've tried googling).

我已经尝试过使用 filezilla 提供的 IP、名称和密码,并且连接没有问题;所以 filezilla 以某种方式使用了正确的加密;我不知道如何判断它在使用什么.

I have tried the ip, name and password i've been given with filezilla and I connect no problems; so filezilla somehow uses the correct encryption; I don't know how to tell what it's using.

帮助?

安德鲁

推荐答案

这里有两个不同的问题.如果您遇到错误的数据包长度问题,那么您可能必须遵循 ssh.net Codeplex 中的指南 讨论以解决谈判.这应该解决初始连接的建立.

You've got two different problems here. If you're getting the bad packet length problem, then you probably have to follow the guide in the ssh.net Codeplex discussion to resolve the negotiation. This should resolve the establishing of the initial connection.

如果您需要使用 ssh 私钥进行连接,那么您必须使用其中一个带有 PrivateKey 对象数组的构造函数.PrivateKey 的构造函数之一采用流,您可以使用如下代码将私钥字符串转换为流:

If you're required to use an ssh private key for connection, then you have to use one of the constructors that takes an array of PrivateKey objects. One of the constructors for a PrivateKey takes a stream, and you can convert the private key string to the stream using code like:

var privKey = new PrivateKey(new MemoryStream(Encoding.ASCII.getBytes(sshPrivateKeyString)));
var sftpclient = new SftpClient(FTPAddress, FTPName, new PrivateKeyFile[] { privKey });

其他机制是使用显式的 PrivateKeyConnectionInfo 实例:

Other mechanisms are to use an explicit PrivateKeyConnectionInfo instance:

var privKey = new PrivateKey(new MemoryStream(Encoding.ASCII.getBytes(sshPrivateKeyString)));
var privConnInfo = new PrivateKeyConnectionInfo(FTPAddress, FTPName, privKey);
var sftpClient = new SftpClient(privConnInfo);

这篇关于ssh.net sftp 坏包长度/打开 SSH 版本 2 RSA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆