SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

FileStream ReadAsync method fails with invalid argument for Golang server

Open anandgmenon opened this issue 7 months ago • 4 comments

I am from the Azure Logic apps team. One of our users have a custom SFTP server implemented in Golang and when we try to read a file we get the following error:

Renci.SshNet.Common.SshException: invalid argument
   at Renci.SshNet.Sftp.SftpSession.RequestRead(Byte[] handle, UInt64 offset, UInt32 length)
   at Renci.SshNet.Sftp.SftpFileStream.Read(Byte[] buffer, Int32 offset, Int32 count)

Our code looks like this. We are using 2024.1.0 version

 using (var sftpClient = new SftpClient(host, port, username, password))
 {
     sftpClient.Connect();

     if (sftpClient.IsConnected)
     {
        var fileMetadata = sftpClient.GetAttributes(filePath);
        var buffer = new byte[fileMetadata.Size];
        using (var fileStream = sftpClient.Open(path: filePath, mode: FileMode.Open, access: FileAccess.Read))
       {
            await fileStream.ReadAsync(buffer, 0, buffer.Length);
       }
     }
     else
     {
         Console.WriteLine("Failed to connect to the SFTP server.");
     }

     // Disconnect
     sftpClient.Disconnect();
 }

On checking the server traces we see this error there runtime error: invalid memory address or nil pointer dereference.

Any idea what could be causing this?

anandgmenon avatar Mar 17 '25 09:03 anandgmenon