Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream example doesn't seem to work properly #1549

Open
yuppox opened this issue Dec 3, 2024 · 2 comments
Open

Stream example doesn't seem to work properly #1549

yuppox opened this issue Dec 3, 2024 · 2 comments

Comments

@yuppox
Copy link

yuppox commented Dec 3, 2024

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?

@Rob-Hague
Copy link
Collaborator

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

@yuppox
Copy link
Author

yuppox commented Dec 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants