Skip to content

FileStream ReadAsync method fails with invalid argument for Golang server #1616

Open
@anandgmenon

Description

@anandgmenon

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?

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