Contains operation for working with SSH Shell.
public class ShellStream : Stream, IAsyncDisposable, IDisposable
Inheritance
Gets a value indicating whether the current stream supports reading.
public override bool CanRead { get; }
Property Value
It is safe to read from Renci.SshNet.ShellStream even after disposal.
CanSeekGets a value indicating whether the current stream supports seeking.
public override bool CanSeek { get; }
Property Value
Gets a value indicating whether the current stream supports writing.
public override bool CanWrite { get; }
Property Value
A value of true does not necessarily mean a write will succeed. It is possible that the channel is closed and/or the stream is disposed by another thread between a call to Renci.SshNet.ShellStream.CanWrite and the call to write.
DataAvailableGets a value indicating whether data is available on the Renci.SshNet.ShellStream to be read.
public bool DataAvailable { get; }
Property Value
Gets the number of bytes currently available for reading.
public override long Length { get; }
Property Value
This property always returns 0, and throws System.NotSupportedException when calling the setter.
public override long Position { get; set; }
Property Value
The setter is called.
Begins the expect.
public IAsyncResult BeginExpect(params ExpectAction[] expectActions)
Parameters
expectActions
ExpectAction[]
The expect actions.
An System.IAsyncResult that references the asynchronous operation.
Begins the expect.
public IAsyncResult BeginExpect(AsyncCallback? callback, params ExpectAction[] expectActions)
Parameters
callback
AsyncCallback?
The callback.
expectActions
ExpectAction[]
The expect actions.
An System.IAsyncResult that references the asynchronous operation.
Begins the expect.
public IAsyncResult BeginExpect(AsyncCallback? callback, object? state, params ExpectAction[] expectActions)
Parameters
callback
AsyncCallback?
The callback.
state
object?
The state.
expectActions
ExpectAction[]
The expect actions.
An System.IAsyncResult that references the asynchronous operation.
Begins the expect.
public IAsyncResult BeginExpect(TimeSpan timeout, AsyncCallback? callback, object? state, params ExpectAction[] expectActions)
Parameters
timeout
TimeSpan
The timeout. Must non-negative or equal to -1 millisecond (for infinite timeout).
callback
AsyncCallback?
The callback.
state
object?
The state.
expectActions
ExpectAction[]
The expect actions.
An System.IAsyncResult that references the asynchronous operation.
Begins the expect.
public IAsyncResult BeginExpect(TimeSpan timeout, int lookback, AsyncCallback? callback, object? state, params ExpectAction[] expectActions)
Parameters
timeout
TimeSpan
The timeout. Must non-negative or equal to -1 millisecond (for infinite timeout).
lookback
int
The amount of data to search through from the most recent data in the buffer, or -1 to always search the entire buffer.
callback
AsyncCallback?
The callback.
state
object?
The state.
expectActions
ExpectAction[]
The expect actions.
An System.IAsyncResult that references the asynchronous operation.
Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed resources.
protected override void Dispose(bool disposing)
Parameters
disposing
bool
true to release both managed and unmanaged resources; false to release only unmanaged resources.
Ends the execute.
public string? EndExpect(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult
The async result.
The text available in the shell up to and including the expected expression.
Expects the specified expression and performs action when one is found.
public void Expect(params ExpectAction[] expectActions)
Parameters
expectActions
ExpectAction[]
The expected expressions and actions to perform.
Expects the specified expression and performs action when one is found.
public void Expect(TimeSpan timeout, params ExpectAction[] expectActions)
Parameters
timeout
TimeSpan
Time to wait for input. Must non-negative or equal to -1 millisecond (for infinite timeout).
expectActions
ExpectAction[]
The expected expressions and actions to perform, if the specified time elapsed and expected condition have not met, that method will exit without executing any action.
If a TimeSpan representing -1 millisecond is specified for the timeout
parameter, this method blocks indefinitely until either the regex matches the data in the buffer, or the stream is closed (via disposal or via the underlying channel closing).
Expects the specified expression and performs action when one is found.
public void Expect(TimeSpan timeout, int lookback, params ExpectAction[] expectActions)
Parameters
timeout
TimeSpan
Time to wait for input. Must non-negative or equal to -1 millisecond (for infinite timeout).
lookback
int
The amount of data to search through from the most recent data in the buffer, or -1 to always search the entire buffer.
expectActions
ExpectAction[]
The expected expressions and actions to perform, if the specified time elapsed and expected condition have not met, that method will exit without executing any action.
If a TimeSpan representing -1 millisecond is specified for the timeout
parameter, this method blocks indefinitely until either the regex matches the data in the buffer, or the stream is closed (via disposal or via the underlying channel closing).
Use the lookback
parameter to constrain the search space to a fixed-size rolling window at the end of the buffer. This can reduce the amount of work done in cases where lots of output from the shell is expected to be received before the matching expression is found.
Note: in situations with high volumes of data and a small value for lookback
, some data may not be searched through. It is recommended to set lookback
to a large enough value to be able to search all data as it comes in, but which still places a limit on the amount of work needed.
Expects the expression specified by text.
public string? Expect(string text)
Parameters
text
string
The text to expect.
The text available in the shell up to and including the expected text, or null if the the stream is closed without a match.
Expects the expression specified by text.
public string? Expect(string text, TimeSpan timeout, int lookback = -1)
Parameters
text
string
The text to expect.
timeout
TimeSpan
Time to wait for input. Must non-negative or equal to -1 millisecond (for infinite timeout).
lookback
int
The amount of data to search through from the most recent data in the buffer, or -1 to always search the entire buffer.
The text available in the shell up to and including the expected expression, or null if the specified time has elapsed or the stream is closed without a match.
If a TimeSpan representing -1 millisecond is specified for the timeout
parameter, this method blocks indefinitely until either the regex matches the data in the buffer, or the stream is closed (via disposal or via the underlying channel closing).
Use the lookback
parameter to constrain the search space to a fixed-size rolling window at the end of the buffer. This can reduce the amount of work done in cases where lots of output from the shell is expected to be received before the matching expression is found.
Note: in situations with high volumes of data and a small value for lookback
, some data may not be searched through. It is recommended to set lookback
to a large enough value to be able to search all data as it comes in, but which still places a limit on the amount of work needed.
Expects the expression specified by regular expression.
public string? Expect(Regex regex)
Parameters
regex
Regex
The regular expression to expect.
The text available in the shell up to and including the expected expression, or null if the stream is closed without a match.
Expects the expression specified by regular expression.
public string? Expect(Regex regex, TimeSpan timeout, int lookback = -1)
Parameters
regex
Regex
The regular expression to expect.
timeout
TimeSpan
Time to wait for input. Must non-negative or equal to -1 millisecond (for infinite timeout).
lookback
int
The amount of data to search through from the most recent data in the buffer, or -1 to always search the entire buffer.
The text available in the shell up to and including the expected expression, or null if the specified timeout has elapsed or the stream is closed without a match.
If a TimeSpan representing -1 millisecond is specified for the timeout
parameter, this method blocks indefinitely until either the regex matches the data in the buffer, or the stream is closed (via disposal or via the underlying channel closing).
Use the lookback
parameter to constrain the search space to a fixed-size rolling window at the end of the buffer. This can reduce the amount of work done in cases where lots of output from the shell is expected to be received before the matching expression is found.
Note: in situations with high volumes of data and a small value for lookback
, some data may not be searched through. It is recommended to set lookback
to a large enough value to be able to search all data as it comes in, but which still places a limit on the amount of work needed.
When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
public override void Flush()
Exceptions
An I/O error occurs.
Reads all of the text currently available in the shell.
public string Read()
Returns
The text available in the shell.
When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
public override int Read(byte[] buffer, int offset, int count)
Parameters
buffer
byte[]
An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset
and (offset
+ count
- 1) replaced by the bytes read from the current source.
offset
int
The zero-based byte offset in buffer
at which to begin storing the data read from the current stream.
count
int
The maximum number of bytes to be read from the current stream.
The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if count
is 0 or the end of the stream has been reached.
The sum of offset
and count
is larger than the buffer length.
buffer
is null.
offset
or count
is negative.
An I/O error occurs.
The stream does not support reading.
Methods were called after the stream was closed.
When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
public override int Read(Span<byte> buffer)
Parameters
buffer
Span<byte>
A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.
The total number of bytes read into the buffer. This can be less than the size of the buffer if that many bytes are not currently available, or zero (0) if the buffer's length is zero or the end of the stream has been reached.
Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
public override int ReadByte()
Returns
The unsigned byte cast to an System.Int32, or -1 if at the end of the stream.
The stream does not support reading.
Methods were called after the stream was closed.
Reads the next line from the shell. If a line is not available it will block and wait for a new line.
public string? ReadLine()
Returns
The line read from the shell.
This method blocks indefinitely until either a line is available in the buffer, or the stream is closed (via disposal or via the underlying channel closing).
When the stream is closed and there are no more newlines in the buffer, this method returns the remaining data (if any) and then null indicating that no more data is in the buffer.
ReadLine(TimeSpan)Reads a line from the shell. If line is not available it will block the execution and will wait for new line.
public string? ReadLine(TimeSpan timeout)
Parameters
timeout
TimeSpan
Time to wait for input. Must non-negative or equal to -1 millisecond (for infinite timeout).
The line read from the shell, or null when no input is received for the specified timeout.
If a TimeSpan representing -1 millisecond is specified for the timeout
parameter, this method blocks indefinitely until either a line is available in the buffer, or the stream is closed (via disposal or via the underlying channel closing).
When the stream is closed and there are no more newlines in the buffer, this method returns the remaining data (if any) and then null indicating that no more data is in the buffer.
Seek(long, SeekOrigin)This method always throws System.NotSupportedException.
public override long Seek(long offset, SeekOrigin origin)
Parameters
offset
long
A byte offset relative to the origin
parameter.
origin
SeekOrigin
A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.
Never.
Always.
This method always throws System.NotSupportedException.
public override void SetLength(long value)
Parameters
value
long
The desired length of the current stream in bytes.
Always.
Writes the specified text to the shell.
public void Write(string? text)
Parameters
text
string?
The text to be written to the shell.
If text
is null, nothing is written. Otherwise, Renci.SshNet.ShellStream.Flush is called after writing the data to the buffer.
The stream is closed.
When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public override void Write(byte[] buffer, int offset, int count)
Parameters
buffer
byte[]
An array of bytes. This method copies count
bytes from buffer
to the current stream.
offset
int
The zero-based byte offset in buffer
at which to begin copying bytes to the current stream.
count
int
The number of bytes to be written to the current stream.
The sum of offset
and count
is greater than the buffer length.
buffer
is null.
offset
or count
is negative.
An I/O error occurred, such as the specified file cannot be found.
The stream does not support writing.
System.IO.Stream.Write(System.Byte[],System.Int32,System.Int32) was called after the stream was closed.
When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public override void Write(ReadOnlySpan<byte> buffer)
Parameters
buffer
ReadOnlySpan<byte>
A region of memory. This method copies the contents of this region to the current stream.
Writes a byte to the current position in the stream and advances the position within the stream by one byte.
public override void WriteByte(byte value)
Parameters
value
byte
The byte to write to the stream.
An I/O error occurs.
The stream does not support writing, or the stream is already closed.
Methods were called after the stream was closed.
Writes the line to the shell.
public void WriteLine(string line)
Parameters
line
string
The line to be written to the shell.
If line
is null, only the line terminator is written. Renci.SshNet.ShellStream.Flush is called once the data is written.
The stream is closed.
Occurs when the channel was closed.
public event EventHandler<EventArgs>? Closed
Event Type
Occurs when data was received.
public event EventHandler<ShellDataEventArgs>? DataReceived
Event Type
Occurs when an error occurred.
public event EventHandler<ExceptionEventArgs>? ErrorOccurred
Event Type
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4