Session.GetFile throws "Recursive calls not allowed"

Advertisement

DaveT
Guest

Session.GetFile throws "Recursive calls not allowed"

Hi,
I'm using the WinSCP 5.18.2-beta Version and I want to download a file via SFTP protocol to stream.

For .Net Standard 2.0 as well as for .Net Framework I´m getting the same errors.

After calling session.GetFile the stream has errors you can see in the attached file StreamErrors.PNG.

Than after calling session.Close the following exception is thrown:
Exception:
System.InvalidOperationException: 'Recursive calls not allowed'

Stack:
at WinSCP.Lock.Enter()
at WinSCP.Session.Dispose()
at ..DownloadFile(String remotePath) in ..\Sftp.cs:line 97
The code I´m using is the following:
using (var session = new Session())
{
    var sessionOptions = this.InitializeSessionOptions();
 
    session.Open(sessionOptions);
 
    session.DebugLogPath = @"c:\test\log.txt";
 
    var remoteFile = session
        .ListDirectory(remotePath)
        .Files
        .Where(x => x.IsDirectory == false)
        .OrderByDescending(x => x.LastWriteTime)
        .FirstOrDefault();
 
    if (remoteFile != null)
    {
        sftpFile.Name = remoteFile.Name;
 
        sftpFile.Content = session.GetFile(remoteFile.FullName);
    }
 
    session.Close();
}

I have also tried to use session.GetFileToDirectory and it works perfectly fine.

So I don´t know if there´s something wrong with my code or could it be something else?

Best,
David

StreamErrors.PNG

  • log.txt (67.44 KB, Private file)
Description: DebugLog

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum