Table of Contents

Method ForwardRemoteDynamicPortAsync

Namespace
SshSharp
Assembly
SshSharp.dll

ForwardRemoteDynamicPortAsync(string, int, Func<string, int, bool>?, CancellationToken)

Remote dynamic port forwarding (ssh -R [bind_address:]port with no destination, OpenSSH 7.6 and later): asks the server to listen on bindAddress:remotePort, and answers each connection made to it as a SOCKS proxy (4, 4a and 5, CONNECT, no authentication), connecting to the destination it names from this machine. It gives the server's side outbound access through this machine's network, for example to reach an internal package mirror from a build host.

public Task<SshRemotePortForwarder> ForwardRemoteDynamicPortAsync(string bindAddress, int remotePort, Func<string, int, bool>? allowDestination = null, CancellationToken cancellationToken = default)

Parameters

bindAddress string

Where the server listens: localhost for its loopback only (what ssh uses by default), an address, or empty for every address (subject to sshd's GatewayPorts).

remotePort int

The port the server listens on; 0 lets it pick one (see RemotePort).

allowDestination Func<string, int, bool>

Decides whether to connect to a requested host and port. The destinations are chosen on the server's side, so whoever can reach the forwarded port there can use this machine's network: like ssh, everything is allowed when this is null. An address is passed in its canonical form, whatever spelling was requested (127.1, 0x7f.1 and ::ffff:127.0.0.1 all arrive as 127.0.0.1; [::1] as ::1). A host name is passed as given, then resolved on this machine and passed again as each address it resolves to: the name and an address must both be allowed, and only the allowed addresses are connected to, so a name that resolves to a refused address is refused too. A filter that throws refuses the destination.

cancellationToken CancellationToken

Cancels the request to the server.

Returns

Task<SshRemotePortForwarder>

Exceptions

SshException

The server refused (sshd's AllowTcpForwarding, or the port is in use).