Why am I getting "Key exchanged failed" message on SFTP Connect?

0 votes
asked Jan 20, 2012 by jjblinky (130 points)
edited Aug 25, 2012

I am writing an automated uploader using Visual Studio 2010 and C#.

Using the code:
Sftp client = new Sftp();
client.LogWriter = new Rebex.FileLogWriter("c:\temp\log.txt", Rebex.LogLevel.Debug);
client.Connect("sftp.server.com");
client.Login(user, pass);

I can connect to the server using filezilla but not using rebex. A "key exchange failed" exception is thrown. "No common algorithms". Log file output below:

2012-01-19 12:57:40.197 Opening log file.
2012-01-19 12:57:40.889 INFO Sftp(1) Info: Connecting to sftp.server.com:22 using Sftp 2.0.4086.0 (trial version).
2012-01-19 12:57:41.383 DEBUG Sftp(1) SSH: Server is 'SSH-2.0-JSCAPE'.
2012-01-19 12:57:41.405 INFO Sftp(1) SSH: Negotiation started.
2012-01-19 12:57:41.681 DEBUG Sftp(1) SSH: Negotiating key.
2012-01-19 12:57:41.807 DEBUG Sftp(1) SSH: Negotiation failed: Rebex.Net.SshException:
Key exchange failed. Connection has been closed by the remote connection end; key exchange failed. No common algorithms. ---> Rebex.Net.SshException: Connection has been closed by the remote connection end; key exchange failed. No common algorithms.
at Rebex.Net.SshSession.cqLugQ(Byte[] , Int32 , Int32 )
at Rebex.Net.SshSession.AapcLiZ(Byte[] , Int32 , Int32 )
at Rebex.Net.SshSession.cDtmAOZ(cMbfbTZ , Object[] )
at Rebex.Net.SshSession.CFLiXJ(ANiLIV )
at wWGvS.miMck.ArwjUr(SshSession , Byte[] , Byte[] , Byte[] , Byte[] , Byte[]& , Byte[]& , Byte[]& )
at Rebex.Net.SshSession.ArwjUr(Byte[] )
--- End of inner exception stack trace ---
at Rebex.Net.SshSession.ArwjUr(Byte[] )

commented Jan 23, 2012 by Lukas Matyska (56,670 points)
edited Jan 23, 2012

Can you please send us the Rebex log file in Verbose level to support@rebex.net? We should be able to determine the cause of the error.

1 Answer

+2 votes
answered Jan 24, 2012 by Lukas Pokorny (109,650 points)
edited Jun 13, 2012

According to the log you sent us, this server only accepts connection from clients that support ZLIB compression. In Rebex SFTP, ZLIB compression is disabled by default. It has to be enabled first in order to connect to the server. This can be done using the following code:

C#

Sftp client = new Sftp();

// Create an instance of SshParameters class 
// to specify desired arguments. 
SshParameters par = new SshParameters();

// Enable transfer compression 
par.Compression = true;

// Connect to the server. 
// The third argument refers to the parameters class. 
client.Connect(hostname, Sftp.DefaultPort, par);

VB.NET

Dim client As New Sftp

' Create an instance of SshParameters class 
' to specify desired arguments. 
Dim par As New SshParameters

' Enable transfer compression 
par.Compression = True

' Connect to the server. 
' The third argument refers to the parameters class. 
client.Connect(hostname, Sftp.DefaultPort, par)
commented Jan 24, 2012 by jjblinky (130 points)
edited Jan 24, 2012

Thank you. This solved the issue and files are successfully transferred.

commented Jun 13, 2012 by Lukas Pokorny (109,650 points)
edited Jun 13, 2012

We added a workaround for this to Rebex SFTP / Rebex SSH Shell 2012 R2. It is now possible to connect to servers which require compression even if it has not been explicitly enabled in Rebex SFTP.

...