0 votes
by (170 points)

We recently upgraded rebex libraries from 2012R2 to latest version, and changed the code to use Rebex.Net.FileTransferClient for both ftp and sftp, instead of Rebex.Net.Ftp and Rebex.Net.Sftp.
Getting remote file stream via sftp using method GetDownloadStream(FullFilePath) worked for all of ours production connections, except for one.
If I acquire the stream using the method GetFile(FullFilePath, remoteFileStream), then it works.

So the issue is fixed, but I would like to get to the root cause, and understend why is it throwing an exception on GetDownloadStream.
What is the difference between getting the stream with GetDownloadStream vs GetFile?
Is it something wrong with the way I use the method, a bug in rebex library, or some configuration on client's sftp server?

The way I'm calling it is straight forward:

FileTransferClient client;
...
using (Stream sourceStream = client.GetDownloadStream(fullFilePath))
{
...
}

Here is some log if that helps:

...
2016-05-18 22:54:41.352 INFO Sftp(2)[1] Command: SSHFXPSTAT (9, '/')
2016-05-18 22:54:41.445 INFO Sftp(2)[1] Response: SSHFXPATTRS (9)
2016-05-18 22:54:41.461 INFO Sftp(2)[1] Command: SSHFXPOPEN (10, '/folder/fileName.txt', 1)
2016-05-18 22:54:41.554 INFO Sftp(2)[1] Response: SSHFXPHANDLE (10, 0x64623832666562362D303830312D343561652D613735342D633839326239613337626235)
2016-05-18 22:54:41.554 DEBUG Sftp(2)[1] Command: SSHFXPREAD (11, 0x64623832666562362D303830312D343561652D613735342D633839326239613337626235, 0, 65536)
2016-05-18 22:54:41.711 DEBUG Sftp(2)[5] SSH: SSH connection closed.
2016-05-18 22:54:41.726 ERROR Sftp(2)[1] SSH: Rebex.Net.SshException: The connection was closed by the server.
at Rebex.Net.SshSession.HPY[Z,D](UNX2 Z, Int32 D, VNX J, D C, Z I, Z W) at Rebex.Net.SshSession.HPY[Z,D](UNX2 Z, D D)
at Rebex.Net.SshChannel.YD[Z,D](UNX`2 Z, D D)
at Rebex.Net.SshChannel.Receive(Byte[] buffer, Int32 offset, Int32 count)
2016-05-18 22:54:41.726 ERROR Sftp(2)[1] SSH: Rebex.Net.SshException: The channel has been closed.
at Rebex.Net.SshChannel.Send(Byte[] buffer, Int32 offset, Int32 count)

Thanks

Applies to: Rebex SFTP

1 Answer

0 votes
by (144k points)

Both GetDownloadStream and GetFile use the same SFTP commands internally (you can easily see this by comparing communication logs of both these methods), but they are slightly different - GetFile pipelines requests to achieve a higher throughput, while GetDownloadStream simply translatest your calls to SFTP commands.

According to the log, you are using GetDownloadStream to read chunks of data 65536 bytes long or larger. There is nothing wrong with that - if this is too large for your server, it should simply return less data. But GetFile uses shorter chunks (by default), so perhaps lowering the chunk size used in your code to 32 KB might help.

In any case, if the server is closing the connection, it looks like a bug. If it doesn't accept client request, it should simply reject it without closing the connection. Is it possible to look into the server log to see whether there is any entry related to this? That might explain what is actually going on.

...