0 votes
ago by (120 points)

Hi,

we're working on a remote update feature with which an embedded software is supposed to be able to retrieve version updates from an update server. We've implemented the basic features with the Rebex libraries. Now we consistently run into this error:

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

Any help is greatly appreciated.

What we've tried / found out
- we're sure the device has internet access (e.g. pinging google works, tracert shows the target gets correctly resolved, telnet returns SSH-2.0...)
- we're sure its an actual SFTP server that does not block the calls (as far as the server is concerned nothing ever tried to communicate)
- whatever we could find on similar topics in this forum
- calling Rebex.Net.ConnectionManagement.ConnectionManager.TryConnect() returns false
- Connections generally worked for a while on different devices, but as soon as the connection failed on one, we cannot restore it anymore. Is there some kind of cache, we could kill?

Logs
(I tried to hide sensible data)

2025-01-23 15:04:49 Opening log file.
2025-01-23 15:04:49 INFO FileLogWriter(1)[116523074] Info: Assembly: Rebex.Common R5.10 for .NET Compact Framework 3.5
2025-01-23 15:04:49 INFO FileLogWriter(1)[116523074] Info: Platform: Windows CE 7.0.2877 32-bit; CLR: 3.5.14223.0
2025-01-23 15:04:49 DEBUG FileLogWriter(1)[116523074] Info: Culture: en; windows-1252
2025-01-23 15:05:26 INFO FileTransferClient(1)[132382830] Info: Connecting to : using Sftp.
2025-01-23 15:05:26 INFO FileTransferClient(1)[132382830] Info: Assembly: Rebex.Sftp R5.10 for .NET Compact Framework 3.5
2025-01-23 15:05:26 INFO FileTransferClient(1)[132382830] Info: Platform: Windows CE 7.0.2877 32-bit; CLR: 3.5.14223.0
2025-01-23 15:05:26 DEBUG FileTransferClient(1)[132382830] Info: Culture: en; windows-1252
2025-01-23 15:05:26 INFO FileTransferClient(1)[132382830] Info: Using proxy none.
2025-01-23 15:05:26 DEBUG FileTransferClient(1)[132382830] Proxy: Connecting to : (no proxy).
2025-01-23 15:05:26 DEBUG FileTransferClient(1)[132382830] Proxy: Connection established.
2025-01-23 15:05:29 ERROR FileTransferClient(1)[132382830] SSH: Rebex.Net.SshException: The connection was closed by the server. Make sure you are connecting to an SSH or SFTP server.
at Rebex.Net.SshSession.aplzc()
at Rebex.Net.SshSession.Negotiate()
at Rebex.Net.Sftp.whjoy.ahcku(ehmzn p0, Boolean p1)
at Rebex.Net.Sftp.hbhug(String p0, Int32 p1, SshParameters p2, ehmzn p3)
at Rebex.Net.Sftp.jpuyt(String p0, Int32 p1, SshParameters p2)
at Rebex.Net.FileTransferClient.Connect(String serverName, Int32 serverPort, FileTransferMode transferMode)
at ... our own code

2025-01-23 15:05:29 ERROR FileTransferClient(1)[132382830] Info: Rebex.Net.SshException: The connection was closed by the server. Make sure you are connecting to an SSH or SFTP server.
at Rebex.Net.SshSession.aplzc()
at Rebex.Net.SshSession.Negotiate()
at Rebex.Net.Sftp.whjoy.ahcku(ehmzn p0, Boolean p1)
at Rebex.Net.Sftp.hbhug(String p0, Int32 p1, SshParameters p2, ehmzn p3)
at Rebex.Net.Sftp.jpuyt(String p0, Int32 p1, SshParameters p2)
at Rebex.Net.FileTransferClient.Connect(String serverName, Int32 serverPort, FileTransferMode transferMode)
at ... our own code

Code
This is basically our code:

_client = new FileTransferClient();
_client.Settings.SslAcceptAllCertificates = true;
// This line is what's causing the error
_client.Connect(settings.FtpHost, settings.FtpPort, FileTransferMode.Sftp);
Applies to: Rebex SFTP

1 Answer

0 votes
ago by (148k points)

This looks like FileTransferClient was able to establish a connection to the server, but did not receive the "SSH-2.0..." string (instead, the connection was closed).

To make sure the issue is not in Rebex libraries, try whether you can reproduce the problem on the Windows Embedded Compact device using just .NET Compact Framework API alone, without using any Rebex code:

// These settings correspond to test.rebex.net:22, which
// should work for you as well if the device has internet
// connectivity. Then, try using your server.
string address = "194.108.117.16";
int port = 22;

using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
    // connect to the server
    socket.Connect(new IPEndPoint(IPAddress.Parse(address), port));

    // receive some data
    var buffer = new byte[1024];
    int bytesReceived = socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);

    // here, bytesReceived is supposed to be a non-zero value
    Assert.NotZero(bytesReceived);
}

If Socket.Receives fails or returns zero, it means that no part of the server’s identification string has been received.

...