<PackageReference Include="SSH.NET" Version="2020.0.2" />

ForwardedPortLocal

Provides functionality for local port forwarding
using Renci.SshNet.Common; using System; namespace Renci.SshNet { public class ForwardedPortLocal : ForwardedPort, IDisposable { private ForwardedPortStatus _status; 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 => _status == ForwardedPortStatus.Started; 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; _status = ForwardedPortStatus.Stopped; } protected override void StartPort() { if (ForwardedPortStatus.ToStarting(ref _status)) try { } catch (Exception) { _status = ForwardedPortStatus.Stopped; throw; } } protected override void StopPort(TimeSpan timeout) { if (ForwardedPortStatus.ToStopping(ref _status)) { base.StopPort(timeout); _status = ForwardedPortStatus.Stopped; } } 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); _isDisposed = true; } } ~ForwardedPortLocal() { Dispose(false); } } }