Skip to content

'The session is not open' in ListDirectoryAsync #1753

@m0a0k0s

Description

@m0a0k0s

On rare occasions, I see 'The session is not open' in ListDirectoryAsync.
The last time I saw it, it was for a server where multiple instances of sftpClient might get created simultaneously with the same username/password, but working with different folders.

SSH.NET 2025.1.0 .Net 9.

My code looks like this:

try
{
    await sftpClient.ConnectAsync(cancellationToken);
	
    await sftpClient.ChangeDirectoryAsync(path, cancellationToken);
    var asyncList = sftpClient.ListDirectoryAsync(path, cancellationToken);
}
finally
{
	if (sftpClient.IsConnected)
		sftpClient.Disconnect();
}

"Type": "System.InvalidOperationException",
"HResult": -2146233079,
"Message": "The session is not open.",
"Source": "Renci.SshNet",
"StackTrace": " at Renci.SshNet.Sftp.SftpSession.SendRequest(SftpRequest request)\r\n at Renci.SshNet.Sftp.SftpSession.GetCanonicalPathAsync(String path, CancellationToken cancellationToken)\r\n at Renci.SshNet.SftpClient.ListDirectoryAsync(String path, CancellationToken cancellationToken)+MoveNext()\r\n at Renci.SshNet.SftpClient.ListDirectoryAsync(String path, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource.GetResult()",
"TargetSite": "Void SendRequest(Renci.SshNet.Sftp.Requests.SftpRequest)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions