Chilkat C# SshTunnel Class Reference

SshTunnel

A software API that makes it possible to create self-managed SSH tunnels in a background thread of an application. Each SSH tunnel object manages two background threads: a thread for accepting new connections, and a tunnel-pool thread for existing (running) SSH tunnels. This API eliminates the need for separate, standalone SSH tunnel processes (such as PUtty). Your application may use SSH tunneling on any computer where it's installed, without the need for additional SSH tunneling software/infrastructure.

Object Creation

(C#)
Chilkat.SshTunnel obj = new Chilkat.SshTunnel();
(VB.NET)
Dim obj As New Chilkat.SshTunnel()

Properties

public string AcceptThreadSessionLogPath {get; set; }

To be documented soon...

public string ConnectLog {get; set; }

Contains log text detailing the establishment of each SSH server connection. This log will continue to grow as new connections are accepted. This property may be cleared by setting it to an empty string.

public int ConnectTimeoutMs {get; set; }

Maximum number of milliseconds to wait when connecting to an SSH server. The default value is 10000 (i.e. 10 seconds).

public string DestHostname {get; set; }

The destination hostname or IP address (in dotted decimal notation) of the service (such as a database server). Data sent through the SSH tunnel is forwarded by the SSH server to this destination. Data received from the destination (by the SSH server) is forwarded back to the client through the SSH tunnel.

public int DestPort {get; set; }

The destination port of the service (such as a database server).

public string HttpProxyAuthMethod {get; set; }

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy authentication method name. Valid choices are "LOGIN" or "NTLM".

public string HttpProxyHostname {get; set; }

If an HTTP proxy is to be used, set this property to the HTTP proxy hostname or IPv4 address (in dotted decimal notation).

public string HttpProxyPassword {get; set; }

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy password.

public int HttpProxyPort {get; set; }

If an HTTP proxy is to be used, set this property to the HTTP proxy port number. (Two commonly used HTTP proxy ports are 8080 and 3128.)

public string HttpProxyUsername {get; set; }

If an HTTP proxy requiring authentication is to be used, set this property to the HTTP proxy login name.

public bool IsAccepting {get; }

true if a background thread is running and accepting connections.

public string LastErrorHtml {get; }

Error information in HTML format for the last method called.

public string LastErrorText {get; }

Error information in plain-text format for the last method called.

public string LastErrorXml {get; }

Error information in XML format for the last method called.

public string ListenBindIpAddress {get; set; }

In most cases, this property does not need to be set. It is provided for cases where it is required to bind the listen socket to a specific IP address (usually for computers with multiple network interfaces or IP addresses). For computers with a single network interface (i.e. most computers), this property should not be set. For multihoming computers, the default IP address is automatically used if this property is not set.

public int ListenPort {get; }

If a port number equal to 0 is passed to BeginAccepting, then this property will contain the actual allocated port number used. Otherwise it is equal to the port number passed to BeginAccepting, or 0 if BeginAccepting was never called.

public int MaxPacketSize {get; set; }

The maximum packet length to be used in the SSH transport protocol. The default value is 32768.

public string OutboundBindIpAddress {get; set; }

In most cases, this property does not need to be set. It is provided for cases where it is required to bind the socket that is to connect to the SSH server (in the background thread) to a specific IP address (usually for computers with multiple network interfaces or IP addresses). For computers with a single network interface (i.e. most computers), this property should not be set. For multihoming computers, the default IP address is automatically used if this property is not set.

public int OutboundBindPort {get; set; }

Unless there is a specific requirement for binding to a specific port, leave this unset (at the default value of 0). (99.9% of all users should never need to set this property.)

public string SocksHostname {get; set; }

The SOCKS4/SOCKS5 hostname or IPv4 address (in dotted decimal notation). This property is only used if the SocksVersion property is set to 4 or 5).

public string SocksPassword {get; set; }

The SOCKS5 password (if required). The SOCKS4 protocol does not include the use of a password, so this does not apply to SOCKS4.

public int SocksPort {get; set; }

The SOCKS4/SOCKS5 proxy port. The default value is 1080. This property only applies if a SOCKS proxy is used (if the SocksVersion property is set to 4 or 5).

public string SocksUsername {get; set; }

The SOCKS4/SOCKS5 proxy username. This property is only used if the SocksVersion property is set to 4 or 5).

public int SocksVersion {get; set; }

SocksVersion May be set to one of the following integer values:

0 - No SOCKS proxy is used. This is the default.
4 - Connect via a SOCKS4 proxy.
5 - Connect via a SOCKS5 proxy.

public string SshHostname {get; set; }

The SSH server's hostname or IP address (in dotted-decimal notation).

public string SshLogin {get; set; }

The SSH server login. Authentication is typically required to establish the SSH tunnel in the background thread.

public string SshPassword {get; set; }

The SSH server password.

public int SshPort {get; set; }

The SSH server's port. The default is 22, and this typically won't change.

public bool TcpNoDelay {get; set; }

Controls whether the TCP_NODELAY socket option is used for the underlying TCP/IP socket. The default value is false. Setting this property equal to true disables the Nagle algorithm and allows for better performance when small amounts of data are sent.

public string TunnelErrors {get; }

Contains the accumulated errors, if any, of the background thread.

public string TunnelThreadSessionLogPath {get; set; }

To be documented soon...

Methods

public bool BeginAccepting(int listenPort);

Starts a background thread for listening on listenPort. A new SSH tunnel is created and managed for each accepted connection. SSH tunnels are managed in a 2nd background thread: the SSH tunnel pool thread.

BeginAccepting starts a background thread that creates a socket, binds to the port, and begins listening. If the bind fails (meaning something else may have already bound to the same port), then the background thread exits. You may check to see if BeginAccepting succeeds by waiting a short time (perhaps 50 millisec) and then examine the IsAccepting property. If it is false, then BeginAccepting failed.

Returns true for success, false for failure.

(C#) SSH Tunnel for Database Connection (such as ADO, ODBC, etc.)

public string GetTunnelsXml();

Returns information about the current set of running SSH tunnels. This is a snapshot of the tunnels at a single point in time. The XML has this format:

<tunnels>
	<t>
		<uniqueId>...</uniqueId>
		<clientIp>...</clientIp>
		<clientPort>...</clientPort>
		<serverIp>...</serverIp>
		<serverPort>...</serverPort>
		<tunnelType>...</tunnelType>
		<login>...</login>
		<password>...</password>
	</t>
	<t>
	...
	</t>
	...
</tunnels>

Returns a null on failure

public bool SaveLastError(string filename);

Saves the last error information to an XML formatted file.

public bool SetSshAuthenticationKey(SshKey key);

Sets the key to be used for public-key SSH authentication. NOTE: The private key is required for authentication. The public-part of the key is installed on the server, and the client must present the private key.

Returns true for success, false for failure.

public bool StopAccepting();

Stops the listen background thread. It is possible to continue accepting connections by re-calling BeginAccepting.

Returns true for success, false for failure.

public bool StopAllTunnels(int maxWaitMs);

Stops all currently running tunnels in the SSH tunnel pool background thread.

Returns true for success, false for failure.

public bool UnlockComponent(string unlockCode);

Unlocks the component. This must be called once prior to calling any other method. A fully-functional 30-day trial is automatically started when an arbitrary string is passed to this method. For example, passing "Hello", or "abc123" will unlock the component for the 1st thirty days after the initial install.

Returns true for success, false for failure.