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

martin
Site Admin
martin avatar
Joined:
Posts:
36,066
Location:
Prague, Czechia

Re: Session.GetFile throws "Recursive calls not allowed"

I do not know what your sftpFile.Content setter does. But you need to dispose the stream returned by Session.GetFile, before you can use the Session instance again. That's true even for calls to Close or Dispose (implied by the using).

See https://winscp.net/eng/docs/library_session_getfile#remarks

Reply with quote

Advertisement

You can post new topics in this forum