Class SshClient
Provides client connection to SSH server.
public class SshClient : BaseClient, IBaseClient, IDisposable
- Inheritance
-
SshClient
- Implements
- Inherited Members
Constructors
SshClient(ConnectionInfo)
Initializes a new instance of the SshClient class.
public SshClient(ConnectionInfo connectionInfo)
Parameters
connectionInfo
ConnectionInfoThe connection info.
Exceptions
- ArgumentNullException
connectionInfo
is null.
SshClient(string, int, string, params IPrivateKeySource[])
Initializes a new instance of the SshClient class.
public SshClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
Parameters
host
stringConnection host.
port
intConnection port.
username
stringAuthentication username.
keyFiles
IPrivateKeySource[]Authentication private key file(s) .
Exceptions
- ArgumentNullException
keyFiles
is null.- ArgumentException
host
is invalid, -or-username
is null or contains only whitespace characters.- ArgumentOutOfRangeException
SshClient(string, int, string, string)
Initializes a new instance of the SshClient class.
public SshClient(string host, int port, string username, string password)
Parameters
host
stringConnection host.
port
intConnection port.
username
stringAuthentication username.
password
stringAuthentication password.
Exceptions
- ArgumentNullException
password
is null.- ArgumentException
host
is invalid, orusername
is null or contains only whitespace characters.- ArgumentOutOfRangeException
SshClient(string, string, params IPrivateKeySource[])
Initializes a new instance of the SshClient class.
public SshClient(string host, string username, params IPrivateKeySource[] keyFiles)
Parameters
host
stringConnection host.
username
stringAuthentication username.
keyFiles
IPrivateKeySource[]Authentication private key file(s) .
Exceptions
- ArgumentNullException
keyFiles
is null.- ArgumentException
host
is invalid, -or-username
is null or contains only whitespace characters.
SshClient(string, string, string)
Initializes a new instance of the SshClient class.
public SshClient(string host, string username, string password)
Parameters
host
stringConnection host.
username
stringAuthentication username.
password
stringAuthentication password.
Exceptions
- ArgumentNullException
password
is null.- ArgumentException
host
is invalid, orusername
is null or contains only whitespace characters.
Properties
ForwardedPorts
Gets the list of forwarded ports.
public IEnumerable<ForwardedPort> ForwardedPorts { get; }
Property Value
Methods
AddForwardedPort(ForwardedPort)
Adds the forwarded port.
public void AddForwardedPort(ForwardedPort port)
Parameters
port
ForwardedPortThe port.
Exceptions
- InvalidOperationException
Forwarded port is already added to a different client.
- ArgumentNullException
port
is null.- SshConnectionException
Client is not connected.
CreateCommand(string)
Creates the command to be executed.
public SshCommand CreateCommand(string commandText)
Parameters
commandText
stringThe command text.
Returns
- SshCommand
SshCommand object.
Exceptions
- SshConnectionException
Client is not connected.
CreateCommand(string, Encoding)
Creates the command to be executed with specified encoding.
public SshCommand CreateCommand(string commandText, Encoding encoding)
Parameters
Returns
- SshCommand
SshCommand object which uses specified encoding.
Remarks
This method will change current default encoding.
Exceptions
- SshConnectionException
Client is not connected.
- ArgumentNullException
commandText
orencoding
is null.
CreateShell(Stream, Stream, Stream)
Creates the shell.
public Shell CreateShell(Stream input, Stream output, Stream extendedOutput)
Parameters
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShell(Stream, Stream, Stream, string, uint, uint, uint, uint, IDictionary<TerminalModes, uint>)
Creates the shell.
public Shell CreateShell(Stream input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModes)
Parameters
input
StreamThe input.
output
StreamThe output.
extendedOutput
StreamThe extended output.
terminalName
stringName of the terminal.
columns
uintThe columns.
rows
uintThe rows.
width
uintThe width.
height
uintThe height.
terminalModes
IDictionary<TerminalModes, uint>The terminal mode.
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShell(Stream, Stream, Stream, string, uint, uint, uint, uint, IDictionary<TerminalModes, uint>?, int)
Creates the shell.
public Shell CreateShell(Stream input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint>? terminalModes, int bufferSize)
Parameters
input
StreamThe input.
output
StreamThe output.
extendedOutput
StreamThe extended output.
terminalName
stringName of the terminal.
columns
uintThe columns.
rows
uintThe rows.
width
uintThe width.
height
uintThe height.
terminalModes
IDictionary<TerminalModes, uint>The terminal mode.
bufferSize
intSize of the internal read buffer.
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShell(Encoding, string, Stream, Stream)
Creates the shell.
public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput)
Parameters
encoding
EncodingThe encoding.
input
stringThe input.
output
StreamThe output.
extendedOutput
StreamThe extended output.
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShell(Encoding, string, Stream, Stream, string, uint, uint, uint, uint, IDictionary<TerminalModes, uint>)
Creates the shell.
public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModes)
Parameters
encoding
EncodingThe encoding.
input
stringThe input.
output
StreamThe output.
extendedOutput
StreamThe extended output.
terminalName
stringName of the terminal.
columns
uintThe columns.
rows
uintThe rows.
width
uintThe width.
height
uintThe height.
terminalModes
IDictionary<TerminalModes, uint>The terminal modes.
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShell(Encoding, string, Stream, Stream, string, uint, uint, uint, uint, IDictionary<TerminalModes, uint>?, int)
Creates the shell.
public Shell CreateShell(Encoding encoding, string input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint>? terminalModes, int bufferSize)
Parameters
encoding
EncodingThe encoding to use to send the input.
input
stringThe input.
output
StreamThe output.
extendedOutput
StreamThe extended output.
terminalName
stringName of the terminal.
columns
uintThe columns.
rows
uintThe rows.
width
uintThe width.
height
uintThe height.
terminalModes
IDictionary<TerminalModes, uint>The terminal mode.
bufferSize
intSize of the internal read buffer.
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShellNoTerminal(Stream, Stream, Stream, int)
Creates the shell without allocating a pseudo terminal,
similar to the ssh -T
option.
public Shell CreateShellNoTerminal(Stream input, Stream output, Stream extendedOutput, int bufferSize = -1)
Parameters
input
StreamThe input.
output
StreamThe output.
extendedOutput
StreamThe extended output.
bufferSize
intSize of the internal read buffer.
Returns
Exceptions
- SshConnectionException
Client is not connected.
CreateShellStream(string, uint, uint, uint, uint, int)
Creates the shell stream.
public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize)
Parameters
terminalName
stringThe
TERM
environment variable.columns
uintThe terminal width in columns.
rows
uintThe terminal width in rows.
width
uintThe terminal width in pixels.
height
uintThe terminal height in pixels.
bufferSize
intThe size of the buffer.
Returns
- ShellStream
The created ShellStream instance.
Remarks
The TERM
environment variable contains an identifier for the text window's capabilities.
You can get a detailed list of these capabilities by using the ‘infocmp’ command.
The column/row dimensions override the pixel dimensions(when nonzero). Pixel dimensions refer to the drawable area of the window.
Exceptions
- SshConnectionException
Client is not connected.
CreateShellStream(string, uint, uint, uint, uint, int, IDictionary<TerminalModes, uint>?)
Creates the shell stream.
public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize, IDictionary<TerminalModes, uint>? terminalModeValues)
Parameters
terminalName
stringThe
TERM
environment variable.columns
uintThe terminal width in columns.
rows
uintThe terminal width in rows.
width
uintThe terminal width in pixels.
height
uintThe terminal height in pixels.
bufferSize
intThe size of the buffer.
terminalModeValues
IDictionary<TerminalModes, uint>The terminal mode values.
Returns
- ShellStream
The created ShellStream instance.
Remarks
The TERM
environment variable contains an identifier for the text window's capabilities.
You can get a detailed list of these capabilities by using the ‘infocmp’ command.
The column/row dimensions override the pixel dimensions(when non-zero). Pixel dimensions refer to the drawable area of the window.
Exceptions
- SshConnectionException
Client is not connected.
CreateShellStreamNoTerminal(int)
Creates the shell stream without allocating a pseudo terminal,
similar to the ssh -T
option.
public ShellStream CreateShellStreamNoTerminal(int bufferSize = -1)
Parameters
bufferSize
intThe size of the buffer.
Returns
- ShellStream
The created ShellStream instance.
Exceptions
- SshConnectionException
Client is not connected.
Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)
Parameters
disposing
booltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
OnDisconnected()
Stops forwarded ports.
protected override void OnDisconnected()
OnDisconnecting()
Called when client is disconnecting from the server.
protected override void OnDisconnecting()
RemoveForwardedPort(ForwardedPort)
Stops and removes the forwarded port from the list.
public void RemoveForwardedPort(ForwardedPort port)
Parameters
port
ForwardedPortForwarded port.
Exceptions
- ArgumentNullException
port
is null.
RunCommand(string)
Creates and executes the command.
public SshCommand RunCommand(string commandText)
Parameters
commandText
stringThe command text.
Returns
- SshCommand
Returns an instance of SshCommand with execution results.
Remarks
This method internally uses asynchronous calls.
Exceptions
- ArgumentException
CommandText property is empty.
- SshException
Invalid Operation - An existing channel was used to execute this command.
- InvalidOperationException
Asynchronous operation is already in progress.
- SshConnectionException
Client is not connected.
- ArgumentNullException
commandText
is null.