sshnet / sshnet/SSH.NET

Stream example doesn't seem to work properly

Open
#1,549 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the stream example using CreateInputStream and ExecuteAsync against an SSH server, then trace why the written data is sometimes absent from command.Result. Compare the behavior with the proposed Flush call and any alternative input approach. Done means the example reliably returns "Hello World!" and supports several input lines.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.