Is it possible to execute multiple SSH commands from a single login session with SSH.NET?

前端 未结 2 1257
小蘑菇
小蘑菇 2021-01-03 01:59

I\'m using C# with SSH.NET and have been able to get a client SSH connection working fine to executing commands across SSH. I can connect to a Linux install I have on a hyp

相关标签:
2条回答
  • 2021-01-03 02:21

    You can implement a shell session using:

    • SshClient.CreateShellStream (ShellStream class) — It gives you one Stream interface, that you can both write and read. This interface is useful, when you want to interact with the shell directly.
    • or SshClient.CreateShell (Shell class) — Where you yourself provide separate streams for input, output and error output. This interface is useful, when you want to link/pipe the input and output to existing streams (like standard input and output or files). Though you can still interact directly, if you use PipeStream. See also SSH.NET doesn't process my shell input commands.

    But using "shell" is really not recommended for automating commands execution. A shell is an interactive feature, that does not have a deterministic behavior.

    You better use an exec channel, see How to run commands on SSH server in C#?

    0 讨论(0)
  • 2021-01-03 02:32

    For the record, this was resolved by using SSH to connect and open a tunnel, then using telnet to do the interactive part. SSH.NET was not mature enough on the interactive side.

    0 讨论(0)
提交回复
热议问题