Class BaseClient
Serves as base class for client implementations, provides common client functionality.
public abstract class BaseClient : IBaseClient, IDisposable
- Inheritance
-
BaseClient
- Implements
- Derived
- Inherited Members
Constructors
BaseClient(ConnectionInfo, bool)
Initializes a new instance of the BaseClient class.
protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)
Parameters
connectionInfo
ConnectionInfoThe connection info.
ownsConnectionInfo
boolSpecified whether this instance owns the connection info.
Remarks
If ownsConnectionInfo
is true, then the
connection info will be disposed when this instance is disposed.
Exceptions
- ArgumentNullException
connectionInfo
is null.
Properties
ConnectionInfo
Gets the connection info.
public ConnectionInfo ConnectionInfo { get; }
Property Value
- ConnectionInfo
The connection info.
Exceptions
- ObjectDisposedException
The method was called after the client was disposed.
IsConnected
Gets a value indicating whether this client is connected to the server.
public virtual bool IsConnected { get; }
Property Value
Exceptions
- ObjectDisposedException
The method was called after the client was disposed.
KeepAliveInterval
Gets or sets the keep-alive interval.
public TimeSpan KeepAliveInterval { get; set; }
Property Value
- TimeSpan
The keep-alive interval. Specify negative one (-1) milliseconds to disable the keep-alive. This is the default value.
Exceptions
- ObjectDisposedException
The method was called after the client was disposed.
Methods
CheckDisposed()
Check if the current instance is disposed.
protected void CheckDisposed()
Exceptions
- ObjectDisposedException
THe current instance is disposed.
Connect()
Connects client to the server.
public void Connect()
Exceptions
- InvalidOperationException
The client is already connected.
- ObjectDisposedException
The method was called after the client was disposed.
- SocketException
Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.
- SshConnectionException
SSH session could not be established.
- SshAuthenticationException
Authentication of SSH session failed.
- ProxyException
Failed to establish proxy connection.
ConnectAsync(CancellationToken)
Asynchronously connects client to the server.
public Task ConnectAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationTokenThe CancellationToken to observe.
Returns
Exceptions
- InvalidOperationException
The client is already connected.
- ObjectDisposedException
The method was called after the client was disposed.
- SocketException
Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.
- SshConnectionException
SSH session could not be established.
- SshAuthenticationException
Authentication of SSH session failed.
- ProxyException
Failed to establish proxy connection.
Disconnect()
Disconnects client from the server.
public void Disconnect()
Exceptions
- ObjectDisposedException
The method was called after the client was disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposing
booltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
~BaseClient()
Finalizes an instance of the BaseClient class.
protected ~BaseClient()
OnConnected()
Called when client is connected to the server.
protected virtual void OnConnected()
OnConnecting()
Called when client is connecting to the server.
protected virtual void OnConnecting()
OnDisconnected()
Called when client is disconnected from the server.
protected virtual void OnDisconnected()
OnDisconnecting()
Called when client is disconnecting from the server.
protected virtual void OnDisconnecting()
SendKeepAlive()
Sends a keep-alive message to the server.
[Obsolete("Use KeepAliveInterval to send a keep-alive message at regular intervals.")]
public void SendKeepAlive()
Remarks
Use KeepAliveInterval to configure the client to send a keep-alive at regular intervals.
Exceptions
- ObjectDisposedException
The method was called after the client was disposed.
Events
ErrorOccurred
Occurs when an error occurred.
public event EventHandler<ExceptionEventArgs>? ErrorOccurred
Event Type
HostKeyReceived
Occurs when host key received.
public event EventHandler<HostKeyEventArgs>? HostKeyReceived
Event Type
ServerIdentificationReceived
Occurs when server identification received.
public event EventHandler<SshIdentificationEventArgs>? ServerIdentificationReceived