Stream example doesn't seem to work properly
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?
Hi, are you using this code exactly, or something else? In particular, are you making sure to dispose the input stream when finished?
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.