Method ForwardLocalPortAsync
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
ForwardLocalPortAsync(IPEndPoint, string, int, CancellationToken)
Local port forwarding (ssh -L): listens on localEndPoint and forwards every connection made to it through
the server to remoteHost:remotePort. Use a loopback address unless other machines should be
able to use the tunnel, and port 0 to let the system pick a free port (see LocalEndPoint).
Forwarding stops when the forwarder or the client is disposed, or the connection ends.
public Task<SshLocalPortForwarder> ForwardLocalPortAsync(IPEndPoint localEndPoint, string remoteHost, int remotePort, CancellationToken cancellationToken = default)
Parameters
localEndPointIPEndPointremoteHoststringremotePortintcancellationTokenCancellationToken
Returns
Exceptions
- SocketException
The local endpoint could not be bound (for example the port is in use).
ForwardLocalPortAsync(IPEndPoint, string, CancellationToken)
Local forwarding to a Unix socket on the server (ssh -L port:/remote/socket): listens on localEndPoint and
forwards every connection made to it to the Unix socket remoteSocketPath on the server
(direct-streamlocal@openssh.com), for example a database or Docker socket there. The forwarder's
RemoteSocketPath is the path; its RemoteHost is empty and
RemotePort 0. sshd's AllowStreamLocalForwarding decides whether the server connects.
public Task<SshLocalPortForwarder> ForwardLocalPortAsync(IPEndPoint localEndPoint, string remoteSocketPath, CancellationToken cancellationToken = default)
Parameters
localEndPointIPEndPointremoteSocketPathstringcancellationTokenCancellationToken
Returns
Exceptions
- SocketException
The local endpoint could not be bound (for example the port is in use).