Class SshSession
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
A shell or command running on the server (an SSH session channel), with its input and output as streams. Start one with
StartShellAsync(SshSessionOptions?, CancellationToken) or StartCommandAsync(string, SshSessionOptions?, CancellationToken); dispose it to close the channel.
public sealed class SshSession : IAsyncDisposable
- Inheritance
-
SshSession
- Implements
- Inherited Members
Remarks
Read StandardOutput and StandardError as the program produces them: output that is not read holds the channel's receive window (2 MiB), and once it is full the server sends nothing more on either stream, as with redirected process streams. With a terminal, the server merges stderr into stdout.
Properties
- ExitSignal
The signal that ended the program (for example
KILL), if any.
- ExitStatus
The program's exit status, once the server has reported it; null before that, or if it ended by a signal.
- HasTerminal
Whether the session has a pseudo-terminal (Terminal).
- StandardError
The program's error output (asynchronous reads only). Empty with a terminal, where the server merges it into StandardOutput.
- StandardInput
The program's input. Writes are sent as they are made; CloseInputAsync(CancellationToken) (or disposing the stream) sends end-of-file. Once the server reports that the program closed its input (
eow@openssh.com), writes fail with an SshException (ChannelClosed), as writing to a pipe whose reader has gone does. OpenSSH's sshd sends that only to clients that identify as OpenSSH, so with it the data is accepted and dropped there instead.
- StandardOutput
The program's output (asynchronous reads only). Ends when the server sends end-of-file. Disposing it while the session goes on tells an OpenSSH server to stop sending output (
eow@openssh.com, as ssh does when its own output closes); output that still arrives is dropped. The program may then get SIGPIPE when it writes.
Methods
- CloseInputAsync(CancellationToken)
Sends end-of-file on StandardInput: the program sees the end of its input (a shell exits).
- DisposeAsync()
Closes the session. A program still running gets a hangup from the server.
- ResizeTerminalAsync(int, int, int, int, CancellationToken)
Tells the server the terminal's new size (
window-change), so full-screen programs redraw for it.
- SendBreakAsync(TimeSpan?, CancellationToken)
Sends a BREAK (RFC 4335), as OpenSSH's
~Bescape does: a serial-line break, which console servers pass on to the device they connect to (to reach a router's ROM monitor, for example), and OpenSSH's sshd sends to a session's terminal. Returns whether the server performed it; servers that do not support it, or a session without a terminal on OpenSSH, answer false.
- SendSignalAsync(string, CancellationToken)
Sends a signal to the program (RFC 4254 section 6.9): a name without the
SIGprefix, such asINT,TERMorKILL, or an extension name (name@domain, RFC 4250), such as OpenSSH'sINFO@openssh.com(SIGINFO, on BSD-derived systems). Current OpenSSH delivers it; older versions and other servers may ignore it, since the request has no reply. With a terminal, writing Ctrl-C (0x03) to StandardInput interrupts the foreground program the way a user would.
- WaitForExitAsync(CancellationToken)
Completes when the server closes the session, after the program has ended and its output has been sent. Output that is never read can keep the server from finishing (see the remarks on SshSession).