Table of Contents

Class BaseClient

Namespace
Renci.SshNet
Assembly
Renci.SshNet.dll

Serves as base class for client implementations, provides common client functionality.

public abstract class BaseClient : IBaseClient, IDisposable

Inheritance

Derived

Implements

Inherited Members

Constructors

BaseClient(ConnectionInfo, bool)

Initializes a new instance of the Renci.SshNet.BaseClient class.

protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)

Parameters

connectionInfo ConnectionInfo

The connection info.

ownsConnectionInfo bool

Specified 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

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

bool

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

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 CancellationToken

The System.Threading.CancellationToken to observe.

Returns

Task

A System.Threading.Tasks.Task that represents the asynchronous connect operation.

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 bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

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() Deprecated

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 Renci.SshNet.BaseClient.KeepAliveInterval to configure the client to send a keep-alive at regular intervals.

Exceptions

ObjectDisposedException

The method was called after the client was disposed.

ErrorOccurred

Occurs when an error occurred.

public event EventHandler<ExceptionEventArgs>? ErrorOccurred

Event Type

EventHandler<ExceptionEventArgs>?

HostKeyReceived

Occurs when host key received.

public event EventHandler<HostKeyEventArgs>? HostKeyReceived

Event Type

EventHandler<HostKeyEventArgs>?

ServerIdentificationReceived

Occurs when server identification received.

public event EventHandler<SshIdentificationEventArgs>? ServerIdentificationReceived

Event Type

EventHandler<SshIdentificationEventArgs>?