+1 vote
by (170 points)

In the following exception:

Rebex.Net.SftpException: The connection was closed by the server. Make sure you are connecting to an SSH or SFTP server.

Is the second sentence a hint or does it indicate that the attempted protocol was wrong? (i.e. FTP vs SFTP) I had a case where this error appeared a few times after switching to Rebex from another SFTP provider, on a task that has been running without error for many months. I was going to just chalk it up to network issues but wanted to make sure since the error seems to imply something else. Thanks.

The rest of the stack trace is:

at Rebex.Net.SshSession.HS()
at Rebex.Net.SshSession.Negotiate()
at Rebex.Net.Sftp.QEB.IS(EEB A)
at Rebex.Net.Sftp.SL(String A, Int32 B, SshParameters C, EEB D)
--- End of inner exception stack trace ---
at Rebex.Net.Sftp.SL(String A, Int32 B, SshParameters C, EEB D)
at Rebex.Net.Sftp.RL(String A, Int32 B, SshParameters C)
at Rebex.Net.Sftp.Connect(String serverName)

Applies to: Rebex SFTP

2 Answers

0 votes
by (58.9k points)

The above exception really indicates that instead of and SSH/SFTP server you are mot probably connecting to an FTP server with implicit TLS/SSL security (so called FTPS).

These two are different protocols, but they often get mixed. Please see our knowledge base article about the SFTP and FTP/SSL protocol differences.

I have tested with our test.rebex.net FTP server on port 990 and it yields exactly the same results when you try to connect with an Sftp client instead of the ( in this case correct) Ftp client.

So instead of your code:

Sftp sftp = new Sftp();
sftp.Connect("server", port); // "test.rebex.net"

please try

Ftp ftp = new Ftp();
ftp.Connect("server", port, SslMode.Implicit); // "test.rebex.net"

and let me know whether you are able to connect to your problematic server now. Both the FTP and SFTP clients are part of Rebex File Transfer Pack. The freee trial can be downloaded at
https://www.rebex.net/file-transfer-pack/download.aspx

by (170 points)
Hi - it turns out that the server in question only has SFTP capability (not vanilla FTP nor FTPS over port 990) and the error only happens sporadically.  Can this error be raised under any circumstances when using only the SFTP Rebex library and a pure SFTP site?
by (58.9k points)
Yes, it can be raised not only when connecting to a non-SSH server but it also when connecting to a real SSH/SFTP server, although then it would indicate some serious trouble between the client and server. Have you already had a chance to create a verbose log as requested in my below answer?
0 votes
by (58.9k points)

Hello,

please create a verbose log using the LogWriter property as described at

https://www.rebex.net/kb/logging/default.aspx

and then post it here. It could possibly be some other problem with the SFTP/SSH server and the exception does not necesarilly mean that you are for sure connecting to some other than SFTP server.

Seeing the verbose log of the communication would help us see what is going on and help you then. Thanks!

by (170 points)
Hi - this was resolved, it turned out that the IP of the server our app was running on (we were downloading files using Rebex from a remote SFTP site) was blacklisted by that site and this error resulted.  I think the error message is misleading in this case since I think the connection is severed/not permitted.  Thanks.
by (58.9k points)
edited by
Thank you for letting us know  that the solution is resolved! And thanks for your suggestion, however, the two cases are unfortunatelly unrecognizable from our point of view - your SFTP server with your blacklisted IP behaves exactly as an FTP server in implicit mode and at the same time the blacklisting seems to be far less likely.
by (147k points)
The misleading error message was actually caused by the fact that the blacklisted client was actually *able to establish a TCP connection* to the server, but when established, the connection was closed. To the client, this really looks like it's not connecting to an SSH/SFTP server at all... Perhaps adding "and check your firewall settings" to the error message would make it more clear?
...