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

ProxyConnector

abstract class ProxyConnector : ConnectorBase
Represents a connector that uses a proxy server to establish a connection to a given SSH endpoint.
using System; using System.Net.Sockets; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Renci.SshNet.Connection { internal abstract class ProxyConnector : ConnectorBase { protected ProxyConnector(ISocketFactory socketFactory) : base(socketFactory) { } protected abstract void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket); protected virtual Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (cancellationToken.Register(delegate(object o) { ((Socket)o).Dispose(); }, socket, false)) HandleProxyConnect(connectionInfo, socket); return Task.CompletedTask; } public override Socket Connect(IConnectionInfo connectionInfo) { Socket socket = SocketConnect(connectionInfo.ProxyHost, connectionInfo.ProxyPort, connectionInfo.Timeout); try { HandleProxyConnect(connectionInfo, socket); return socket; } catch (Exception) { socket.Shutdown(SocketShutdown.Both); socket.Dispose(); throw; } } [AsyncStateMachine(typeof(<ConnectAsync>d__4))] public override Task<Socket> ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken) { <ConnectAsync>d__4 stateMachine = default(<ConnectAsync>d__4); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Socket>.Create(); stateMachine.<>4__this = this; stateMachine.connectionInfo = connectionInfo; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } } }