Class SshRemotePortForwarder
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
A remote port forwarding (ssh -R) started by ForwardRemotePortAsync(string, int, string, int, CancellationToken): the server listens on
BindAddress:RemotePort, and each connection made to it is relayed to LocalHost:LocalPort
as reached from this machine. A remote dynamic forwarding (ForwardRemoteDynamicPortAsync(string, int, Func<string, int, bool>?, CancellationToken),
IsDynamic) instead answers each connection as a SOCKS proxy and connects where it asks, and a forwarding to a handler
(ForwardRemotePortAsync(string, int, Func<SshForwardedConnection, CancellationToken, Task>, int, CancellationToken))
passes each connection to the application's code. Dispose it to cancel the forwarding on the server and close the forwarded
connections.
public sealed class SshRemotePortForwarder : IAsyncDisposable
- Inheritance
-
SshRemotePortForwarder
- Implements
- Inherited Members
Properties
- ActiveConnections
How many forwarded connections are open now.
- BindAddress
The address the server listens on, as requested (
localhostfor its loopback, empty for every address).
- HandlerShutdownTimeout
For a forwarding to a handler (IsHandler): how long DisposeAsync() waits for the handlers it cancelled to return before it closes the connections of those still running under them. 5 seconds by default; Zero closes them at once, and InfiniteTimeSpan waits as long as they take. Set it before disposing; it does not apply to other forwardings, whose connections are closed at once.
- IsDynamic
Whether this is a remote dynamic forwarding (
ssh -R port): each forwarded connection is a SOCKS request answered here, and LocalHost is empty and LocalPort 0.
- IsHandler
Whether connections go to a handler in this process (ForwardRemotePortAsync(string, int, Func<SshForwardedConnection, CancellationToken, Task>, int, CancellationToken)) rather than to a host and port or, for a dynamic forwarding, where each connection asks.
- LocalHost
Where each forwarded connection goes, as reached from this machine; empty for a dynamic forwarding or one to a handler.
- MaxConnections
The most connections this forwarding serves at once: a handler's
maxConnections, above which the server's channels are refused until some end; MaxValue (no limit of its own) for a forwarding to a host and port or a dynamic one. MaxForwardedConnections applies across all forwardings either way.
- RemotePort
The port the server listens on (the one it picked when 0 was asked for).
Methods
- DisposeAsync()
Cancels the forwarding on the server (
cancel-tcpip-forward) and closes every forwarded connection. For a forwarding to a handler, the token each handler was given is cancelled, and this waits up to HandlerShutdownTimeout (5 seconds by default) for the handlers to return; the connections of any still running then are closed under them, and this returns without waiting for them further. A connection the server opened before the cancel, but that reaches this forwarder only after disposal has gathered the connections it waits for, is closed without being served.