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.