Skip to content

"Bad message" error when Renci SSH.NET calls SSH_FXP_OPENDIR #521

@n0h

Description

@n0h

We have a .NET application that uses the Renci SSH.NET library to connect to an SFTP server.

In one of our test environments we started using PowerShell OpenSSH as the SFTP server. It was working fine as of v0.0.4.0. But it broke in v0.0.5.0, and we have tested the later releases through v0.0.8.0 with the same results. We have tried SSH.NET versions 2014.4.6.0 and 2016.0.0 and see the same behavior. Other SFTP clients like WinSCP and FileZilla do not encounter the errors.

Our .NET application encounters the error when calling the following method:
Renci.SshNet.SftpClient.ListDirectory(string path, Action<int> listCallback = null)

This method internally calls Renci.SshNet.Sftp.SftpSession.RequestOpenDir(String path, Boolean nullOnError) which tries SSH_FXP_OPENDIR, and that is where the Renci.SshNet.Common.SshException gets thrown.

Here is the stack trace where the error occurs:

Renci.SshNet.dll!Renci.SshNet.Sftp.SftpSession.RequestOpenDir.AnonymousMethod__37(Renci.SshNet.Sftp.Responses.SftpStatusResponse response) Line 567          C#
Renci.SshNet.dll!Renci.SshNet.Sftp.Requests.SftpRequest.Complete(Renci.SshNet.Sftp.Responses.SftpResponse response) Line 30            C#
Renci.SshNet.dll!Renci.SshNet.Sftp.SftpSession.HandleResponse(Renci.SshNet.Sftp.Responses.SftpResponse response) Line 1159        C#
Renci.SshNet.dll!Renci.SshNet.Sftp.SftpSession.OnDataReceived(uint dataTypeCode, byte[] data) Line 226                C#
Renci.SshNet.dll!Renci.SshNet.SubsystemSession.Channel_DataReceived(object sender, Renci.SshNet.Common.ChannelDataEventArgs e) Line 189          C#
Renci.SshNet.dll!Renci.SshNet.Channels.Channel.OnData(byte[] data) Line 331 C#
Renci.SshNet.dll!Renci.SshNet.Channels.Channel.OnChannelData(object sender, Renci.SshNet.MessageEventArgs<Renci.SshNet.Messages.Connection.ChannelDataMessage> e) Line 686          C#
Renci.SshNet.dll!Renci.SshNet.Session.OnChannelDataReceived(Renci.SshNet.Messages.Connection.ChannelDataMessage message) Line 1531         C#
Renci.SshNet.dll!Renci.SshNet.Session.HandleMessage(Renci.SshNet.Messages.Connection.ChannelDataMessage message) Line 1185         C#
[External Code]
Renci.SshNet.dll!Renci.SshNet.Session.HandleMessageCore(Renci.SshNet.Messages.Message message) Line 16  C#
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1767       C#
Renci.SshNet.dll!Renci.SshNet.Session.Connect.AnonymousMethod__4() Line 587        C#
Renci.SshNet.dll!Renci.SshNet.Session.ExecuteThread.AnonymousMethod__3c(object o) Line 25          C#

Here is the stack trace where the exception is caught:

Renci.SshNet.dll!Renci.SshNet.Sftp.SftpSession.RequestOpenDir(string path, bool nullOnError) Line 578                C#
Renci.SshNet.dll!Renci.SshNet.SftpClient.InternalListDirectory(string path, System.Action<int> listCallback) Line 1589             C#
Renci.SshNet.dll!Renci.SshNet.SftpClient.ListDirectory(string path, System.Action<int> listCallback) Line 451                C#

We are logging this against PowerShell OpenSSH rather than SSH.NET because SSH.NET can connect to other SFTP servers without errors, and it could connect to v0.0.4.0 of PowerShell OpenSSH without errors.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions