SSH Tunneling with Chilkat SshTunnel

SshTunnel provides local SSH port forwarding without launching an external ssh program or a separate tunnel daemon. The application owns the SshTunnel object, while Chilkat creates and manages the background threads that listen for local clients, maintain tunnel activity, and relay data.

Chilkat SshTunnel process and network architecture A separate client process on the local computer connects to a listener managed by Chilkat background threads inside the application's process. The traffic crosses an encrypted SSH connection to a remote SSH server, which then connects to the destination service. LOCAL COMPUTER Client ProcessBrowser, database client,mail client, or other appconnects to 127.0.0.1:port Your Application Process Application threadCreates, configures, and controlsSshTunnel Chilkat-managed background work• listener thread• SSH tunnel-pool thread• client/tunnel threadsNo external ssh executableor tunnel daemon is launched. method calls / properties local TCP REMOTE SYSTEMS SSH Server ProcessTerminates the SSH connectionand opens destination TCPconnections from its network. Destination ServiceDatabase, web server, API,mail server, or other TCP service Encrypted SSHapplication computer → SSH server ordinary TCP

Logical traffic path and execution ownership. The local client is commonly a separate process, while the tunnel implementation runs inside the process that created SshTunnel.

Chilkat object or managed thread Separate process or application code SSH server or remote network component Destination service Local-computer boundary
Chilkat implementation model: BeginAccepting starts a listener background thread. Accepted tunnels are managed by a second background thread, the SSH tunnel-pool thread, and active clients are serviced by Chilkat-managed client threads. These are internal threads in the application process.

Four locations to keep separate

PartTypical locationExecution formRole
Client applicationLocal computerUsually a separate processConnects to the local listening port or speaks SOCKS to it.
SshTunnelLocal computer, inside your application processApplication object plus Chilkat-managed background threadsListens locally, creates SSH channels, and relays bytes.
SSH serverRemote computer or gatewaySeparate SSH server processTerminates SSH and opens connections to destinations.
Destination serviceRemote server, internal host, or sometimes the SSH server itselfSeparate server processProvides the actual database, HTTP, mail, or other TCP service.

What “local” means

“Local port forwarding” describes where the listening socket exists: on the application computer. The client using that socket may be another process on the same computer, another component in the same process, or—when the listener is bound to a non-loopback interface—a client on another computer. For a tunnel intended only for local use, bind the listener to 127.0.0.1.

Choose the forwarding mode

Common API sequence

Create the SshTunnel object and set connection, proxy, logging, or binding properties that must apply before connecting.
Call Connect(sshHostname, sshPort), or ConnectThroughSsh for a multi-hop configuration.
Verify the expected SSH host key using HostKeyFingerprint, then authenticate with AuthenticatePw, AuthenticatePk, or another supported authentication method.
Configure static or dynamic forwarding properties.
Call BeginAccepting(listenPort). Check IsAccepting; when port 0 is requested, read the allocated port from ListenPort.
When finished, stop accepting new clients, disconnect active clients as needed, and call CloseTunnel(true) for final shutdown.
Encryption boundary: SSH protects traffic between the local application process and the SSH server. The connection from the SSH server to the final destination is an ordinary TCP connection unless the application protocol itself uses TLS or another form of encryption.