C# Class Renci.SshNet.Channels.Channel

Represents base class for SSH channel implementations.
Inheritance: IDisposable
Datei anzeigen Open project: sshnet/SSH.NET Class Usage Examples

Public Methods

Method Description
Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

SendData ( byte data ) : void

Sends a SSH_MSG_CHANNEL_DATA message with the specified payload.

SendData ( byte data, int offset, int size ) : void

Sends a SSH_MSG_CHANNEL_DATA message with the specified payload.

When the size of the data to send exceeds the maximum packet size or the remote window size does not allow the full data to be sent, then this method will send the data in multiple chunks and will wait for the remote window size to be adjusted when it's zero.

This is done to support SSH servers will a small window size that do not agressively increase their window size. We need to take into account that there may be SSH servers that only increase their window size when it has reached zero.

SendEof ( ) : void

Sends a SSH_MSG_CHANNEL_EOF message to the remote server.

Protected Methods

Method Description
Channel ( ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize ) : System

Initializes a new Channel instance.

Close ( ) : void

Closes the channel, waiting for the SSH_MSG_CHANNEL_CLOSE message to be received from the server.

Dispose ( bool disposing ) : void

Releases unmanaged and - optionally - managed resources

InitializeRemoteInfo ( uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize ) : void
OnChannelException ( Exception ex ) : void

Called when an Exception occurs while processing a channel message.

This method will in turn invoke OnErrorOccured(System.Exception), and raise the Exception event.

OnClose ( ) : void

Called when channel is closed by the server.

OnData ( byte data ) : void

Called when channel data is received.

OnDisconnected ( ) : void
OnEof ( ) : void

Called when channel has no more data to receive.

OnErrorOccured ( Exception exp ) : void
OnExtendedData ( byte data, uint dataTypeCode ) : void

Called when channel extended data is received.

OnFailure ( ) : void

Called when channel request failed.

OnRequest ( RequestInfo info ) : void

Called when channel request received.

OnSuccess ( ) : void

Called when channel request was successful

OnWindowAdjust ( uint bytesToAdd ) : void

Called when channel window need to be adjust.

RaiseExceptionEvent ( Exception exception ) : void

Raises Channel.Exception event.

SendMessage ( Message message ) : void

Sends SSH message to the server.

WaitOnHandle ( WaitHandle waitHandle ) : void

Waits for the handle to be signaled or for an error to occurs.

Private Methods

Method Description
AdjustDataWindow ( byte messageData ) : void
CreateChannelClosedException ( ) : InvalidOperationException
CreateRemoteChannelInfoNotAvailableException ( ) : InvalidOperationException
GetDataLengthThatCanBeSentInMessage ( int messageLength ) : int

Determines the length of data that currently can be sent in a single message.

OnChannelClose ( object sender, MessageEventArgs e ) : void
OnChannelData ( object sender, MessageEventArgs e ) : void
OnChannelEof ( object sender, MessageEventArgs e ) : void
OnChannelExtendedData ( object sender, MessageEventArgs e ) : void
OnChannelFailure ( object sender, MessageEventArgs e ) : void
OnChannelRequest ( object sender, MessageEventArgs e ) : void
OnChannelSuccess ( object sender, MessageEventArgs e ) : void
OnChannelWindowAdjust ( object sender, MessageEventArgs e ) : void
Session_Disconnected ( object sender, EventArgs e ) : void
Session_ErrorOccured ( object sender, ExceptionEventArgs e ) : void
TrySendMessage ( Message message ) : bool

Sends a message to the server.

This methods returns false when the attempt to send the message results in a SocketException or a SshException.

Method Details

Channel() protected method

Initializes a new Channel instance.
protected Channel ( ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize ) : System
session ISession The session.
localChannelNumber uint The local channel number.
localWindowSize uint Size of the window.
localPacketSize uint Size of the packet.
return System

Close() protected method

Closes the channel, waiting for the SSH_MSG_CHANNEL_CLOSE message to be received from the server.
protected Close ( ) : void
return void

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
return void

Dispose() protected method

Releases unmanaged and - optionally - managed resources
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

InitializeRemoteInfo() protected method

protected InitializeRemoteInfo ( uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize ) : void
remoteChannelNumber uint
remoteWindowSize uint
remotePacketSize uint
return void

OnChannelException() protected method

Called when an Exception occurs while processing a channel message.
This method will in turn invoke OnErrorOccured(System.Exception), and raise the Exception event.
protected OnChannelException ( Exception ex ) : void
ex System.Exception The .
return void

OnClose() protected method

Called when channel is closed by the server.
protected OnClose ( ) : void
return void

OnData() protected method

Called when channel data is received.
protected OnData ( byte data ) : void
data byte The data.
return void

OnDisconnected() protected method

protected OnDisconnected ( ) : void
return void

OnEof() protected method

Called when channel has no more data to receive.
protected OnEof ( ) : void
return void

OnErrorOccured() protected method

protected OnErrorOccured ( Exception exp ) : void
exp System.Exception
return void

OnExtendedData() protected method

Called when channel extended data is received.
protected OnExtendedData ( byte data, uint dataTypeCode ) : void
data byte The data.
dataTypeCode uint The data type code.
return void

OnFailure() protected method

Called when channel request failed.
protected OnFailure ( ) : void
return void

OnRequest() protected method

Called when channel request received.
protected OnRequest ( RequestInfo info ) : void
info Renci.SshNet.Messages.Connection.RequestInfo Channel request information.
return void

OnSuccess() protected method

Called when channel request was successful
protected OnSuccess ( ) : void
return void

OnWindowAdjust() protected method

Called when channel window need to be adjust.
protected OnWindowAdjust ( uint bytesToAdd ) : void
bytesToAdd uint The bytes to add.
return void

RaiseExceptionEvent() protected method

Raises Channel.Exception event.
protected RaiseExceptionEvent ( Exception exception ) : void
exception System.Exception The exception.
return void

SendData() public method

Sends a SSH_MSG_CHANNEL_DATA message with the specified payload.
public SendData ( byte data ) : void
data byte The payload to send.
return void

SendData() public method

Sends a SSH_MSG_CHANNEL_DATA message with the specified payload.

When the size of the data to send exceeds the maximum packet size or the remote window size does not allow the full data to be sent, then this method will send the data in multiple chunks and will wait for the remote window size to be adjusted when it's zero.

This is done to support SSH servers will a small window size that do not agressively increase their window size. We need to take into account that there may be SSH servers that only increase their window size when it has reached zero.

public SendData ( byte data, int offset, int size ) : void
data byte An array of containing the payload to send.
offset int The zero-based offset in at which to begin taking data from.
size int The number of bytes of to send.
return void

SendEof() public method

Sends a SSH_MSG_CHANNEL_EOF message to the remote server.
The channel is closed.
public SendEof ( ) : void
return void

SendMessage() protected method

Sends SSH message to the server.
protected SendMessage ( Message message ) : void
message Message The message.
return void

WaitOnHandle() protected method

Waits for the handle to be signaled or for an error to occurs.
protected WaitOnHandle ( WaitHandle waitHandle ) : void
waitHandle System.Threading.WaitHandle The wait handle.
return void