开发者

SSH command from C# client redirecting files

The original Unix implementation simply did something like this:

ssh [batchname] < [inputfilename] > [outputfilename]

I need to be able to do the same thing from a windows machine running an application written in C#. I've tried using SharpSsh, which includes input and output streams, but they don't seem to work.

How can I pipe the input and output files/streams using SharpSsh (or any othe开发者_JS百科r .Net library)?


Figured it out. Either the application running or SSH itself expects a ctrl-d to signal the end of the input. At that point, the output stream can be read without hanging.


If anyone else is looking for this, check out CliWrap. It lets you run processes and pipe inputs/outputs really easily.

await using var input = File.Open("input.txt");
await using var output = File.Create("output.txt");
await using var error = File.Create("error.txt");

var cmd = input | Cli.Wrap("child.exe").WithArguments("foo bar") | (output, error);

await cmd.ExecuteAsync();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜