Thanks Martin! Indeed, I forgot to dispose the stream...
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
sftpFile.Contentsetter does. But you need to dispose the stream returned by
Session.GetFile, before you can use the
Sessioninstance again. That's true even for calls to
Dispose(implied by the
session.GetFilethe stream has errors you can see in the attached file
session.Closethe following exception is thrown:
System.InvalidOperationException: 'Recursive calls not allowed'
at ..DownloadFile(String remotePath) in ..\Sftp.cs:line 97
using (var session = new Session())
var sessionOptions = this.InitializeSessionOptions();
session.DebugLogPath = @"c:\test\log.txt";
var remoteFile = session
.Where(x => x.IsDirectory == false)
.OrderByDescending(x => x.LastWriteTime)
if (remoteFile != null)
sftpFile.Name = remoteFile.Name;
sftpFile.Content = session.GetFile(remoteFile.FullName);
session.GetFileToDirectoryand it works perfectly fine.