Bad Packet Length - SftpClient.Connect()

Sep 6, 2011 at 8:39 PM

Hi,

I have downloaded the latest version of your source code today, as my application requires SFTP connection and found your library to be the right one to facilitate my work. I am trying to connect to establish an SFTP connection from my application. When I invoke the function SftpClient.Connect() method it's returning me the error "Bad Packet Length". I was able to use the same credentials and successfully connect using Putty, FileZilla and WinSCP clients. May I ask you to please let me know if there are any settings that I am missing for connecting through the code.

Thanks for your help in advance.

~geekmaster

Coordinator
Sep 7, 2011 at 6:34 AM

Hey,

 

From my experience, usually I was getting this error when I had encryption wrong.

Can you please check what is encryptions supported by your server?

May be I have one of the encryptions wrong and server chooses this one to work with.

 

Thanks,

Oleg

Sep 7, 2011 at 1:43 PM

Hi,

We are using MD5 with RSA encryption on the server. Please let us know if there is a way to explicitly set the encryption before trying to establish communication with the server.

Thanks,

Santosh

Coordinator
Sep 8, 2011 at 4:37 PM

If you downloaded latest source you can either look at the test cases or here is one example:

            var connectionInfo = new PasswordConnectionInfo(Resources.HOST, 22, Resources.USERNAME, Resources.PASSWORD);
            connectionInfo.Encryptions.Clear();
            connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); }));

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                client.Disconnect();
            }

The example above tells client to use 3des-cbc encryption only.

 

Hope it helps,

Thanks,

Oleg

Jan 6, 2012 at 3:34 PM
Edited Jan 6, 2012 at 3:36 PM

Hi,

I'm also getting the Bad Packet Length error when I connect to a remote SFTP server. The funny thing is I was connecting fine and now it has stopped working. I can connect with FileZilla. The exact exception message is: "Error opening connection to 'server'. ---> Renci.SshNet.Common.SshConnectionException: Bad Packet length 3327009809". The error occurs at "SftpClient.Connect()". I tried to use the code that was submitted in your previous post but it did not work and I also got the latest version of SSH.Net from 12/7/2011. I'm very new to SSH so I'm doing a lot of trial and error right now. As I was surfing the interent looking for possible reasons for this I ran across an article explaining that sometimes the SSH Server sends welcome messages that are not being interpreted correctly by the client which can give wildly large packet sizes such as mine. I see the max packet size is 35000 but my packet size is 3,327,009,809 that is a huge difference. I could be on the completely wrong path but thought it was worth a shot looking into. The web site I'm referring to is www.snailbook.com/faq/sftp-corruption.auto.html.

Edit: I would also like to add that the encryption used is the same as the server.

Any help you can give would be greatly appreciated.

Richard

Coordinator
Jan 10, 2012 at 2:31 PM

Hi,

 

I think here is again, the problem with encryption.

Try to use either different encryption or connect to different server and see if it works.

 

Thanks,

Oleg

Jan 10, 2012 at 3:06 PM

Thank you for your response! You are correct, I found that the encryption algorithms that I needed were in the Connection Info lists but when it performed the linq join then selected the first or default it was selecting an algorithm that must not have worked even though the server said that it was supported. I also noticed that I had to clear the HostKeyAlgorithms, KeyExchangeAlgorithms, Encryptions, and HmacAlgorithms to get it to work. To perform this I had to change the access modifier on KeyExchangeDiffieHellmanGroupExchangeSha1 from internal to public so I could access from outside the project. Thank you again for quick response and for all your work on this project, it would have taken me forever to get SFTP working on my own.

Thanks,

Richard