Table of Contents

Class SshProxy

Namespace
SshSharp
Assembly
SshSharp.dll

An HTTP or SOCKS proxy to reach the SSH server through, for networks that allow outbound connections only that way. Set it as Proxy or Proxy, or open a stream with ConnectAsync(string, int, CancellationToken) and pass it to ConnectAsync(Stream, SshClientOptions, bool, CancellationToken).

public sealed class SshProxy
Inheritance
SshProxy
Inherited Members

Remarks

Destination host names are sent to the proxy, which resolves them (as curl --socks5-hostname does), so names the proxy's network knows work, and local DNS does not see them. HTTP Basic and SOCKS 5 credentials cross the network to the proxy in the clear (as with every client of these protocols), so use them only with a proxy on a network you trust. For a transport these protocols do not cover, FromConnector(Func<string, int, CancellationToken, ValueTask<Stream>>) takes your own.

Properties

Credentials

The credentials sent to the proxy, if any (for SOCKS 4, just the user id).

Host

The proxy's host name or address; empty for a Custom one, which connects as it chooses.

Port

The proxy's port; 0 for a Custom one.

Type

The kind of proxy.

Methods

ConnectAsync(string, int, CancellationToken)

Connects to the proxy and asks it for a connection to host:port. The returned stream carries that connection; disposing it closes the connection to the proxy.

FromConnector(Func<string, int, CancellationToken, ValueTask<Stream>>)

A proxy that is your own code: connector receives the host and port to reach (the SSH server, or the first JumpHosts or ProxyJump host) and returns a connected, duplex stream to it, such as a cloud provider's WebSocket tunnel, a named pipe or an in-memory transport. It goes wherever an SshProxy goes: Proxy, Proxy and the DI package's client options.

FromUri(Uri)

A proxy from a URI, as proxy settings are usually written: http://proxy:3128, socks5://proxy:1080, socks5h:// (the same: names are always resolved by the proxy), socks4:// or socks4a://, with optional user:password@ (percent-encoded). The port defaults to 8080 for HTTP and 1080 for SOCKS.

Http(string, int, NetworkCredential?)

An HTTP proxy, reached with CONNECT; credentials are sent with Basic authentication.

Socks4(string, int, string?)

A SOCKS 4 proxy (4a for host names), with an optional user id.

Socks5(string, int, NetworkCredential?)

A SOCKS 5 proxy; credentials are sent with username and password authentication (RFC 1929).

ToString()

The proxy's address and kind (only the kind for a custom one); never the credentials.