Table of Contents

Method ExpectAsync

Namespace
SshSharp
Assembly
SshSharp.dll

ExpectAsync(string, CancellationToken)

Waits until the output contains text (an ordinal match).

public Task<SshExpectMatch> ExpectAsync(string text, CancellationToken cancellationToken = default)

Parameters

text string

The text to wait for, for example a prompt.

cancellationToken CancellationToken

A timeout or cancellation.

Returns

Task<SshExpectMatch>

The output before the match, and the match; both are consumed.

Exceptions

EndOfStreamException

The output ended without the text appearing (Pending holds what came).

OperationCanceledException

Cancelled; nothing is lost, and the output read so far stays in Pending.

ExpectAsync(Regex, CancellationToken)

Waits until the output matches pattern.

public Task<SshExpectMatch> ExpectAsync(Regex pattern, CancellationToken cancellationToken = default)

Parameters

pattern Regex

The pattern to wait for, for example new Regex(@"[$#] $") for a shell prompt.

cancellationToken CancellationToken

A timeout or cancellation.

Returns

Task<SshExpectMatch>

The output before the match, and the match with its groups; both are consumed.

Exceptions

EndOfStreamException

The output ended without a match (Pending holds what came).

OperationCanceledException

Cancelled; nothing is lost, and the output read so far stays in Pending.

RegexMatchTimeoutException

Matching took longer than the pattern's MatchTimeout; the output stays in Pending.