Table of Contents

Method ForwardLocalUnixSocketAsync

Namespace
SshSharp
Assembly
SshSharp.dll

ForwardLocalUnixSocketAsync(string, string, int, CancellationToken)

Local forwarding from a Unix socket (ssh -L /local/socket:host:port): creates the Unix socket localSocketPath here and forwards every connection made to it through the server to remoteHost:remotePort. The socket file is created owner-only (mode 0600, as ssh's default StreamLocalBindMask gives; on Windows an ACL with only the current user), and removed when the forwarder stops. Unix sockets work on Linux, macOS and Windows 10 and later.

public Task<SshLocalSocketForwarder> ForwardLocalUnixSocketAsync(string localSocketPath, string remoteHost, int remotePort, CancellationToken cancellationToken = default)

Parameters

localSocketPath string
remoteHost string
remotePort int
cancellationToken CancellationToken

Returns

Task<SshLocalSocketForwarder>

Exceptions

SocketException

The socket could not be created: a file exists at the path, or its directory does not.

ArgumentException

The path is longer than the platform allows for a socket (about 104 to 108 bytes).

ForwardLocalUnixSocketAsync(string, string, int, UnixFileMode, CancellationToken)

Local forwarding from a Unix socket to remoteHost:remotePort, as ForwardLocalUnixSocketAsync(string, string, int, CancellationToken), with the socket file's permissions given, as ssh_config's StreamLocalBindMask sets them: for example UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.GroupRead | UnixFileMode.GroupWrite (0660) lets the owner's group connect too. Connecting to a Unix socket takes write permission. The mode is set before the socket accepts connections. On Windows the socket file is always restricted to the current user, whatever the mode.

public Task<SshLocalSocketForwarder> ForwardLocalUnixSocketAsync(string localSocketPath, string remoteHost, int remotePort, UnixFileMode socketMode, CancellationToken cancellationToken = default)

Parameters

localSocketPath string
remoteHost string
remotePort int
socketMode UnixFileMode
cancellationToken CancellationToken

Returns

Task<SshLocalSocketForwarder>

Exceptions

ArgumentOutOfRangeException

socketMode has bits other than the nine permission bits (0777).

SocketException

The socket could not be created: a file exists at the path, or its directory does not.

ArgumentException

The path is longer than the platform allows for a socket (about 104 to 108 bytes).

ForwardLocalUnixSocketAsync(string, string, CancellationToken)

Local forwarding from a Unix socket to a Unix socket on the server (ssh -L /local/socket:/remote/socket): creates the Unix socket localSocketPath here (owner-only, removed when the forwarder stops) and forwards every connection made to it to remoteSocketPath on the server, for example to use the server's Docker socket with a local client.

public Task<SshLocalSocketForwarder> ForwardLocalUnixSocketAsync(string localSocketPath, string remoteSocketPath, CancellationToken cancellationToken = default)

Parameters

localSocketPath string
remoteSocketPath string
cancellationToken CancellationToken

Returns

Task<SshLocalSocketForwarder>

Exceptions

SocketException

The socket could not be created: a file exists at the path, or its directory does not.

ArgumentException

The path is longer than the platform allows for a socket (about 104 to 108 bytes).

ForwardLocalUnixSocketAsync(string, string, UnixFileMode, CancellationToken)

Local forwarding from a Unix socket to a Unix socket on the server, as ForwardLocalUnixSocketAsync(string, string, CancellationToken), with the socket file's permissions given (see ForwardLocalUnixSocketAsync(string, string, int, UnixFileMode, CancellationToken)).

public Task<SshLocalSocketForwarder> ForwardLocalUnixSocketAsync(string localSocketPath, string remoteSocketPath, UnixFileMode socketMode, CancellationToken cancellationToken = default)

Parameters

localSocketPath string
remoteSocketPath string
socketMode UnixFileMode
cancellationToken CancellationToken

Returns

Task<SshLocalSocketForwarder>

Exceptions

ArgumentOutOfRangeException

socketMode has bits other than the nine permission bits (0777).

SocketException

The socket could not be created: a file exists at the path, or its directory does not.

ArgumentException

The path is longer than the platform allows for a socket (about 104 to 108 bytes).