Method ForwardDynamicPortAsync
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
ForwardDynamicPortAsync(IPEndPoint, CancellationToken)
Dynamic port forwarding (ssh -D): runs a SOCKS proxy on localEndPoint (SOCKS 4, 4a and 5, CONNECT,
no authentication). Each application connection names its destination, and the server makes the connection, so host names are
resolved on the server's side. Use a loopback address: the proxy has no authentication, so anyone who can reach it can use the
server's network. To listen beyond loopback, require a password with
ForwardDynamicPortAsync(IPEndPoint, NetworkCredential?, CancellationToken).
public Task<SshDynamicPortForwarder> ForwardDynamicPortAsync(IPEndPoint localEndPoint, CancellationToken cancellationToken = default)
Parameters
localEndPointIPEndPointcancellationTokenCancellationToken
Returns
Exceptions
- SocketException
The local endpoint could not be bound (for example the port is in use).
ForwardDynamicPortAsync(IPEndPoint, NetworkCredential?, CancellationToken)
Dynamic port forwarding (ssh -D) with a SOCKS proxy that requires a user name and password: SOCKS 5 username/password
authentication (RFC 1929). Applications must give credentials; SOCKS 4 and 4a, which have no passwords, and SOCKS
5 clients that do not authenticate, are refused. Use it when the proxy must listen beyond loopback (for a container, a VM or other
machines). The credentials only keep out those who do not know them: RFC 1929 sends them in clear text, and the application's
traffic to the proxy is not encrypted either (only the hop from the server on is), so anyone who can watch the local network can
read and reuse them. Prefer a loopback address whenever the applications run on this machine. Without credentials (null), the same
as ForwardDynamicPortAsync(IPEndPoint, CancellationToken).
public Task<SshDynamicPortForwarder> ForwardDynamicPortAsync(IPEndPoint localEndPoint, NetworkCredential? credentials, CancellationToken cancellationToken = default)
Parameters
localEndPointIPEndPointWhere the proxy listens.
credentialsNetworkCredentialThe user name and password applications must give (Domain is not used), each 1 to 255 bytes in UTF-8; null for no authentication. Only keyed digests of them are kept, and attempts are compared in constant time.
cancellationTokenCancellationTokenCancels starting the forwarder.
Returns
Exceptions
- ArgumentException
The user name or password is empty or longer than 255 bytes in UTF-8.
- SocketException
The local endpoint could not be bound (for example the port is in use).