Table of Contents

Method OpenChannelAsync

Namespace
SshSharp
Assembly
SshSharp.dll

OpenChannelAsync(string, ReadOnlyMemory<byte>, CancellationToken)

Opens a channel of any type (RFC 4254 section 5.1), for a server's own or vendor channel types that SshSharp has no API for, and returns it. typeSpecificData is sent as is after the channel type, so encode it as the type defines (an SSH string is a big-endian uint32 length followed by its bytes). Disposing the channel closes it; ShutdownSendAsync(CancellationToken) ends only the writing side.

public Task<SshCustomChannel> OpenChannelAsync(string channelType, ReadOnlyMemory<byte> typeSpecificData = default, CancellationToken cancellationToken = default)

Parameters

channelType string

The channel type: printable US-ASCII without spaces or commas, at most 64 characters (RFC 4251 section 6), for example my-channel@example.com. Session channels are opened with StartCommandAsync(string, SshSessionOptions?, CancellationToken), StartShellAsync(SshSessionOptions?, CancellationToken) or StartSubsystemAsync(string, SshSessionOptions?, CancellationToken), not here.

typeSpecificData ReadOnlyMemory<byte>

The bytes that follow the channel type in SSH_MSG_CHANNEL_OPEN; empty when the type has none.

cancellationToken CancellationToken

Cancels waiting for the server's answer.

Returns

Task<SshCustomChannel>

Examples

await using var channel = await client.OpenChannelAsync("my-channel@example.com");
await channel.Stream.WriteAsync(request);
await channel.ShutdownSendAsync();
var reply = new MemoryStream();
await channel.Stream.CopyToAsync(reply);

Exceptions

ArgumentException

channelType is not a valid name or is session, or typeSpecificData is longer than 32,000 bytes.

SshException

The server refused to open the channel (for example, it does not know the type).