Class Session
- Namespace
- Renci.SshNet
- Assembly
- Renci.SshNet.dll
Provides functionality to connect and interact with SSH server.
public class Session : IDisposable
Inheritance
Implements
Inherited Members
Properties
ClientInitMessage
Gets the client init message.
public Message ClientInitMessage { get; }
Property Value
ClientVersion
Gets the client version string.
public string ClientVersion { get; }
Property Value
ConnectionInfo
Gets the connection info.
public ConnectionInfo ConnectionInfo { get; }
Property Value
IsConnected
Gets a value indicating whether the session is connected.
public bool IsConnected { get; }
Property Value
Remarks
This methods returns true in all but the following cases:
- The Renci.SshNet.Session is disposed.
- The
SSH_MSG_DISCONNECT
message - which is used to disconnect from the server - has been sent. - The client has not been authenticated successfully.
- The listener thread - which is used to receive messages from the server - has stopped.
- The socket used to communicate with the server is no longer connected.
ServerVersion
Gets the server version string.
public string ServerVersion { get; }
Property Value
SessionId
Gets the session id.
public byte[] SessionId { get; }
Property Value
- byte[]
SessionSemaphore
Gets the session semaphore that controls session channels.
public SemaphoreSlim SessionSemaphore { get; }
Property Value
Methods
Connect()
Connects to the server.
public void Connect()
Exceptions
- 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 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
- 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 from the server.
public void Disconnect()
Remarks
This sends a SSH_MSG_DISCONNECT message to the server, waits for the server to close the socket on its end and subsequently closes the client socket.
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.
RegisterMessage(string)
Registers SSH message with the session.
public void RegisterMessage(string messageName)
Parameters
messageName
string-
The name of the message to register with the session.
UnRegisterMessage(string)
Unregister SSH message from the session.
public void UnRegisterMessage(string messageName)
Parameters
messageName
string-
The name of the message to unregister with the session.
ChannelCloseReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelCloseMessage message received
public event EventHandler<MessageEventArgs<ChannelCloseMessage>> ChannelCloseReceived
Event Type
ChannelDataReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelDataMessage message received
public event EventHandler<MessageEventArgs<ChannelDataMessage>> ChannelDataReceived
Event Type
ChannelEofReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelEofMessage message received
public event EventHandler<MessageEventArgs<ChannelEofMessage>> ChannelEofReceived
Event Type
ChannelExtendedDataReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelExtendedDataMessage message received
public event EventHandler<MessageEventArgs<ChannelExtendedDataMessage>> ChannelExtendedDataReceived
Event Type
ChannelFailureReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelFailureMessage message received
public event EventHandler<MessageEventArgs<ChannelFailureMessage>> ChannelFailureReceived
Event Type
ChannelOpenConfirmationReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelOpenConfirmationMessage message received
public event EventHandler<MessageEventArgs<ChannelOpenConfirmationMessage>> ChannelOpenConfirmationReceived
Event Type
ChannelOpenFailureReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelOpenFailureMessage message received
public event EventHandler<MessageEventArgs<ChannelOpenFailureMessage>> ChannelOpenFailureReceived
Event Type
ChannelOpenReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelOpenMessage message received
public event EventHandler<MessageEventArgs<ChannelOpenMessage>> ChannelOpenReceived
Event Type
ChannelRequestReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelRequestMessage message received
public event EventHandler<MessageEventArgs<ChannelRequestMessage>> ChannelRequestReceived
Event Type
ChannelSuccessReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelSuccessMessage message received
public event EventHandler<MessageEventArgs<ChannelSuccessMessage>> ChannelSuccessReceived
Event Type
ChannelWindowAdjustReceived
Occurs when Renci.SshNet.Messages.Connection.ChannelWindowAdjustMessage message received
public event EventHandler<MessageEventArgs<ChannelWindowAdjustMessage>> ChannelWindowAdjustReceived
Event Type
Disconnected
Occurs when session has been disconnected from the server.
public event EventHandler<EventArgs> Disconnected
Event Type
ErrorOccured
Occurs when an error occurred.
public event EventHandler<ExceptionEventArgs> ErrorOccured
Event Type
HostKeyReceived
Occurs when host key received.
public event EventHandler<HostKeyEventArgs> HostKeyReceived
Event Type
RequestFailureReceived
Occurs when Renci.SshNet.Messages.Connection.RequestFailureMessage message received
public event EventHandler<MessageEventArgs<RequestFailureMessage>> RequestFailureReceived
Event Type
RequestSuccessReceived
Occurs when Renci.SshNet.Messages.Connection.RequestSuccessMessage message received
public event EventHandler<MessageEventArgs<RequestSuccessMessage>> RequestSuccessReceived
Event Type
ServerIdentificationReceived
Occurs when server identification received.
public event EventHandler<SshIdentificationEventArgs> ServerIdentificationReceived
Event Type
UserAuthenticationBannerReceived
Occurs when Renci.SshNet.Messages.Authentication.BannerMessage message is received from the server.
public event EventHandler<MessageEventArgs<BannerMessage>> UserAuthenticationBannerReceived