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

Stream example doesn't seem to work properly

Open yuppox opened this issue 1 year ago • 2 comments

Hi, I am trying to use this stream example:

{
    client.Connect();

    // Make the server echo back the input file with "cat"
    using (SshCommand command = client.CreateCommand("cat"))
    {
        Task executeTask = command.ExecuteAsync(CancellationToken.None);

        using (Stream inputStream = command.CreateInputStream())
        {
            inputStream.Write("Hello World!"u8);
        }

        await executeTask;

        Console.WriteLine(command.ExitStatus); // 0
        Console.WriteLine(command.Result); // "Hello World!"
    }
}

However, I am having issues with it. Frequently, the data doesn't reach the client. So, instead of "Hello World!" the result is empty.

I am trying to use it to write several lines of input via SSH. My client is already connected before I call this.

I tried forcing inputStream.Flush() but it doesn't work reliably and might not make any difference.

How can I fix this? Is there another approach to consider?

yuppox avatar Dec 03 '24 02:12 yuppox

Hi, are you using this code exactly, or something else? In particular, are you making sure to dispose the input stream when finished?

Rob-Hague avatar Dec 03 '24 22:12 Rob-Hague

Hi.

I used the code as-is. The stream should be disposed of after the using block processes. I tried adding Flush and Close after the write but it didn't solve the problem.

yuppox avatar Dec 04 '24 03:12 yuppox