0 votes
by (120 points)
edited

I am new to FTP\SFTP components, and am attempting to use your Sample Winforms application to connect to a secure public ftp server. I get the same error in your example application that I got in my application, which is "Key exchange failed. Error while sending packet" I can use coreftp lite to connect and navigate just fine. The first time it connects, it asks me to accept their key. Other than that, it works just like any other FTP program. I am not given a pre-shared key or any of that mess. Using your example, I chose verbose logging and got the following:

14:39:16.206 Debug SSH: Negotiation failed: Rebex.Net.SshException: Key exchange failed. Error while sending packet. ---> Rebex.Net.SshException: Error while sending packet. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.SshSession.1685053200(11634889349 , Boolean )
   --- End of inner exception stack trace ---
by (147k points)
Please try usig Sftp object's LogWriter property to create a communication log (as described at http://www.rebex.net/kb/logging.aspx) and either mail it to us or add it to your question. We should be able to tell more then.

1 Answer

0 votes
by (147k points)
edited

It turned out that this was caused by an inability to perform "diffie-hellman-group14-sha1" key exchange during SSH negotiation. Although the reason for this is not clear, it doesn't appear to be caused by Rebex SFTP - other applications such as FileZilla exhibit the same problem. Forcing "diffie-hellman-group1-sha1" solves the issue:

C#:

SshParameters parameters = new SshParameters();
// Use weaker Diffie-Hellman negotiation
parameters.KeyExchangeAlgorithms = SshKeyExchangeAlgorithm.DiffieHellmanGroup1SHA1; 
// Turn off ZLIB compression (not related to this problem, but other users had problems with this)
parameters.Compression = false;

Sftp sftp = new Sftp();
// Pass the parameters to the Connect method
sftp.Connect("ftp.availity.com", 9922, parameters);
...