0 votes
by (150 points)

Hi,
we have some issues when using SFTP GetDownloadStream(). We can see the Open command fine on the SFTP server and we receive the file. It never sends any Close command though, so after some time the SFTP server is full of open streams and it stops working. We are using Rebex 5.X in C# .Net 4.5.2

Is this a known bug? If so, it it fixed in later versions?

Applies to: Rebex SFTP

1 Answer

0 votes
by (148k points)
selected by
 
Best answer

I tried running the following code, and according to the log, the stream is getting closed as expected:

using (var sftp = new Sftp())
{
    sftp.LogWriter = new ConsoleLogWriter(LogLevel.Debug);
    sftp.Connect("test.rebex.net");
    sftp.Login("demo", "password");

    using (var stream = sftp.GetDownloadStream("readme.txt"))
    {
        var reader = new StreamReader(stream);
        string text = reader.ReadToEnd();
        Console.WriteLine(text);
    }
}

Make sure that you always close the stream by calling Close, Dispose (possibly via using as in the code above). Otherwise, the stream would only get closed when .NET's garbage collector finalizes the stream instance, which could take seconds, minutes or more.

...