<PackageReference Include="SSH.NET" Version="2016.0.0-beta2" />

ForwardedPortLocal

Provides functionality for local port forwarding
using System; using System.Threading; namespace Renci.SshNet { public class ForwardedPortLocal : ForwardedPort, IDisposable { private EventWaitHandle _listenerTaskCompleted; private bool _isDisposed; public string BoundHost { get; set; } public uint BoundPort { get; set; } public string Host { get; set; } public uint Port { get; set; } public override bool IsStarted { get { if (_listenerTaskCompleted != null) return !_listenerTaskCompleted.WaitOne(0); return false; } } public ForwardedPortLocal(uint boundPort, string host, uint port) : this(string.Empty, boundPort, host, port) { } public ForwardedPortLocal(string boundHost, string host, uint port) : this(boundHost, 0, host, port) { } public ForwardedPortLocal(string boundHost, uint boundPort, string host, uint port) { if (boundHost == null) throw new ArgumentNullException("boundHost"); if (host == null) throw new ArgumentNullException("host"); boundPort.ValidatePort("boundPort"); port.ValidatePort("port"); BoundHost = boundHost; BoundPort = boundPort; Host = host; Port = port; } protected override void StartPort() { } protected override void StopPort(TimeSpan timeout) { if (IsStarted) base.StopPort(timeout); } protected override void CheckDisposed() { if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected override void Dispose(bool disposing) { if (!_isDisposed) { base.Dispose(disposing); if (disposing) { EventWaitHandle listenerTaskCompleted = _listenerTaskCompleted; if (listenerTaskCompleted != null) { listenerTaskCompleted.Dispose(); _listenerTaskCompleted = null; } } _isDisposed = true; } } ~ForwardedPortLocal() { Dispose(false); } } }