Class SshTunnel
- All Implemented Interfaces:
AutoCloseable
Create SSH tunnels for secure local, fixed-destination, dynamic, and multi-hop forwarding.
Chilkat.SshTunnel creates SSH tunnels for forwarding local
client connections through an SSH server to a destination service, such as a
database server or other TCP service. It supports fixed destination
forwarding, dynamic SOCKS-style port forwarding, password and public-key
authentication, keyboard-interactive authentication, proxy connections to the
SSH server, multi-hop SSH connections, background accept threads,
tunnel/client logging, secure secret lookup, and connection diagnostics.
Local port forwarding
Listen on a local port and forward accepted client connections through an SSH server to a configured destination host and port.
Dynamic forwarding
Enable SOCKS-style dynamic port forwarding when each client connection should choose its own destination through the tunnel.
SSH authentication
Authenticate to the SSH server using passwords, public keys, password-plus-key, secure password lookup, or keyboard-interactive authentication.
Proxy and multi-hop access
Reach the SSH server through HTTP or SOCKS proxies, or build tunnels through an existing SSH connection for multi-hop scenarios.
Accept and manage clients
Start accepting client connections in the background, inspect current state, stop accepting new clients, and disconnect active tunnel clients.
Logging and diagnostics
Use accept logs, tunnel logs, current-state XML, and
LastErrorText to troubleshoot SSH connection, forwarding,
authentication, or client-connection problems.
Common pattern:
Configure the SSH server, authentication method, local listen settings, and
destination forwarding options, then call BeginAccepting to
start the tunnel. Local client applications connect to the tunnel's listen
port, and SshTunnel forwards the traffic through SSH. Use
Chilkat.SshTunnel for port forwarding; use
Chilkat.Ssh for direct SSH sessions, commands, channels, and
shell access.
Start with the SSH Tunneling Guide
Learn how static forwarding, dynamic SOCKS forwarding, multi-hop tunneling, proxies, background threads, lifecycle management, and troubleshooting fit together.
A shorter API-focused introduction is also available in the SshTunnel Class Overview.
</section>
Event-capable: long-running methods report progress through a ProgressListener installed
with setProgressListener(ProgressListener), onAbortCheck(BooleanSupplier),
onPercentDone(IntPredicate) or onProgressInfo(BiConsumer).
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidauthenticatePk(String username, SshKey privateKey)Authenticates with the SSH server using public-key authentication.voidauthenticatePw(String login, String password)Authenticates with the SSH server usingloginandpassword.voidauthenticatePwPk(String username, String password, SshKey privateKey)Authenticates with an SSH server that requires both a password and a private key.voidauthenticateSecPw(SecureString login, SecureString password)Performs the same password authentication as, but receives the login and password inauthenticatePw(String, String)SecureStringobjects.voidauthenticateSecPwPk(SecureString username, SecureString password, SshKey privateKey)Performs the same combined password-and-private-key authentication as, but receives the username and password inauthenticatePwPk(String, String, SshKey)SecureStringobjects.voidbeginAccepting(int listenPort)Creates and starts the local listener onlistenPort.voidcloseTunnel(boolean waitForThreads)Disconnects active tunnel clients and stops the tunnel-manager thread.voidEstablishes the SSH connection that will carry tunneled traffic.voidconnectThroughSsh(Ssh ssh, String hostname, int port)Connects to a second SSH server through the existing connected and authenticatedSshobject supplied inssh.continueKeyboardAuth(String response)Continues a keyboard-interactive authentication exchange started by.startKeyboardAuth(String)voiddisconnectAllClients(boolean waitForThreads)Disconnects all active tunnel clients while leaving the local listener and SSH connection available.booleanSet this property tofrom another thread to request that the currently running foreground operation be aborted.trueContains the in-memory activity log for the background listener thread started by.beginAccepting(int)Specifies the local file path where activity from the background listener thread is written.Specifies the SSH client-identification string sent when connecting to the SSH server.Specifies the local directory where a separate log file is created for each tunnel client.intSpecifies the maximum number of milliseconds allowed for establishing the SSH connection.Returns an XML snapshot describing the tunnel manager, SSH channels, and current tunnel clients.Specifies the destination hostname or IP address for fixed-destination port forwarding.intSpecifies the TCP port of the destination service used for fixed-destination forwarding, such as the port of a database server.booleanControls whether the listener performs fixed-destination or dynamic port forwarding.booleanEnables automatic resolution of credentials from secure storage provided by the operating system.Contains the SSH server host-key fingerprint afterorconnect(String, int)establishes the SSH connection.connectThroughSsh(Ssh, String, int)Specifies the authentication method to use when the outbound connection to the SSH server passes through an HTTP proxy that requires authentication.Specifies the optional Windows domain used for NTLM authentication with the HTTP proxy.Specifies the hostname or IPv4 address of the HTTP proxy through which the outbound connection to the SSH server is made.Specifies the password used to authenticate with the HTTP proxy for the outbound connection to the SSH server.intSpecifies the TCP port of the HTTP proxy used for the outbound connection to the SSH server.Specifies the username used to authenticate with the HTTP proxy for the outbound connection to the SSH server.intSpecifies a stall timeout, in milliseconds, for tunnel data-transfer operations.Specifies the password required from inbound SOCKS5 clients whenisgetDynamicPortForwarding().trueSpecifies the username required from inbound SOCKS clients whenisgetDynamicPortForwarding().truebooleanwhen the local listener thread is running and accepting inbound TCP connections; otherwisetrue.falsebooleanControls whether activity from the background listener thread is retained in memory.booleanControls whether SSH tunnel-thread activity is retained in memory.Specifies the local IPv4 address to which the tunnel's listening socket is bound.intContains the local TCP port used by the listener started by.beginAccepting(int)Specifies the local IP address to which the outbound socket is bound before connecting to the SSH server.intSpecifies the local TCP port to bind before making the outbound connection to the SSH server.booleanControls which IP version is preferred when a hostname resolves to both IPv4 and IPv6 addresses.Returns the installed listener, ornull.Specifies the hostname or IPv4 address of the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.Specifies the password for authenticating with an outbound SOCKS5 proxy used to reach the SSH server.intSpecifies the TCP port of the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.Specifies the username for the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.intSelects whether the outbound connection to the SSH server is made through a SOCKS proxy.intSets the receive-buffer size for the underlying TCP socket.intSets the send-buffer size for the underlying TCP socket.booleanControls theTCP_NODELAYsocket option for the underlying TCP connection.Contains the in-memory activity log for the SSH tunnel and client-manager threads.Specifies the local file path where SSH tunnel-thread activity is written.Provides optional behavior for uncommon requirements.booleanReturnswhen the SSH transport used by this tunnel is connected; otherwise returnstrue.falsevoidonAbortCheck(BooleanSupplier callback)Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it.voidonPercentDone(IntPredicate callback)Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it.voidonProgressInfo(BiConsumer<String,String> callback)Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds.voidsetAbortCurrent(boolean value)Sets theAbortCurrentproperty; seegetAbortCurrent().voidsetAcceptLog(String value)Sets theAcceptLogproperty; seegetAcceptLog().voidsetAcceptLogPath(String value)Sets theAcceptLogPathproperty; seegetAcceptLogPath().voidsetAllowedAlgorithms(JsonObject json)Restricts the SSH connection to the algorithms specified injson.voidsetClientIdentifier(String value)Sets theClientIdentifierproperty; seegetClientIdentifier().voidsetClientLogDir(String value)Sets theClientLogDirproperty; seegetClientLogDir().voidsetConnectTimeoutMs(int value)Sets theConnectTimeoutMsproperty; seegetConnectTimeoutMs().voidsetDestHostname(String value)Sets theDestHostnameproperty; seegetDestHostname().voidsetDestPort(int value)Sets theDestPortproperty; seegetDestPort().voidsetDynamicPortForwarding(boolean value)Sets theDynamicPortForwardingproperty; seegetDynamicPortForwarding().voidsetEnableSecrets(boolean value)Sets theEnableSecretsproperty; seegetEnableSecrets().voidsetHttpProxyAuthMethod(String value)Sets theHttpProxyAuthMethodproperty; seegetHttpProxyAuthMethod().voidsetHttpProxyDomain(String value)Sets theHttpProxyDomainproperty; seegetHttpProxyDomain().voidsetHttpProxyHostname(String value)Sets theHttpProxyHostnameproperty; seegetHttpProxyHostname().voidsetHttpProxyPassword(String value)Sets theHttpProxyPasswordproperty; seegetHttpProxyPassword().voidsetHttpProxyPort(int value)Sets theHttpProxyPortproperty; seegetHttpProxyPort().voidsetHttpProxyUsername(String value)Sets theHttpProxyUsernameproperty; seegetHttpProxyUsername().voidsetIdleTimeoutMs(int value)Sets theIdleTimeoutMsproperty; seegetIdleTimeoutMs().voidsetInboundSocksPassword(String value)Sets theInboundSocksPasswordproperty; seegetInboundSocksPassword().voidsetInboundSocksUsername(String value)Sets theInboundSocksUsernameproperty; seegetInboundSocksUsername().voidsetKeepAcceptLog(boolean value)Sets theKeepAcceptLogproperty; seegetKeepAcceptLog().voidsetKeepTunnelLog(boolean value)Sets theKeepTunnelLogproperty; seegetKeepTunnelLog().voidsetListenBindIpAddress(String value)Sets theListenBindIpAddressproperty; seegetListenBindIpAddress().voidsetOutboundBindIpAddress(String value)Sets theOutboundBindIpAddressproperty; seegetOutboundBindIpAddress().voidsetOutboundBindPort(int value)Sets theOutboundBindPortproperty; seegetOutboundBindPort().voidsetPreferIpv6(boolean value)Sets thePreferIpv6property; seegetPreferIpv6().voidsetProgressListener(ProgressListener listener)Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.voidsetSocksHostname(String value)Sets theSocksHostnameproperty; seegetSocksHostname().voidsetSocksPassword(String value)Sets theSocksPasswordproperty; seegetSocksPassword().voidsetSocksPort(int value)Sets theSocksPortproperty; seegetSocksPort().voidsetSocksUsername(String value)Sets theSocksUsernameproperty; seegetSocksUsername().voidsetSocksVersion(int value)Sets theSocksVersionproperty; seegetSocksVersion().voidsetSoRcvBuf(int value)Sets theSoRcvBufproperty; seegetSoRcvBuf().voidsetSoSndBuf(int value)Sets theSoSndBufproperty; seegetSoSndBuf().voidsetTcpNoDelay(boolean value)Sets theTcpNoDelayproperty; seegetTcpNoDelay().voidsetTunnelLog(String value)Sets theTunnelLogproperty; seegetTunnelLog().voidsetTunnelLogPath(String value)Sets theTunnelLogPathproperty; seegetTunnelLogPath().voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().startKeyboardAuth(String login)Begins keyboard-interactive authentication forlogin.voidstopAccepting(boolean waitForThread)Stops the local listener so that no new client connections are accepted.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
SshTunnel
public SshTunnel()Creates a newSshTunnelobject.
-
-
Method Details
-
getAbortCurrent
public boolean getAbortCurrent()Set this property tofrom another thread to request that the currently running foreground operation be aborted. For example, it can interrupt a synchronoustruethat is waiting for an SSH server response.connect(String, int)This property does not stop the background listener or terminate established background tunnel clients.
Do not assume the property is automatically reset after an operation is aborted. It may remain
; set it back totruebefore starting another operation.false- Returns:
- the value of the
AbortCurrentproperty
-
setAbortCurrent
public void setAbortCurrent(boolean value)Sets theAbortCurrentproperty; seegetAbortCurrent().- Parameters:
value- the new value
-
getAcceptLog
Contains the in-memory activity log for the background listener thread started by.beginAccepting(int)The log is populated only when
isgetKeepAcceptLog().true- Returns:
- the value of the
AcceptLogproperty
-
setAcceptLog
Sets theAcceptLogproperty; seegetAcceptLog().- Parameters:
value- the new value (notnull)
-
getAcceptLogPath
Specifies the local file path where activity from the background listener thread is written.This file-based log is separate from the in-memory
.getAcceptLog()- Returns:
- the value of the
AcceptLogPathproperty
-
setAcceptLogPath
Sets theAcceptLogPathproperty; seegetAcceptLogPath().- Parameters:
value- the new value (notnull)
-
getClientIdentifier
Specifies the SSH client-identification string sent when connecting to the SSH server.Starting in Chilkat v9.5.0.99, the default is
SSH-2.0-Chilkat_followed by the Chilkat version number, such asSSH-2.0-Chilkat_9.5.0.99.The identifier should begin with
SSH-2.0-. Some SSH servers disconnect clients that send an invalid identification string.- Returns:
- the value of the
ClientIdentifierproperty
-
setClientIdentifier
Sets theClientIdentifierproperty; seegetClientIdentifier().- Parameters:
value- the new value (notnull)
-
getClientLogDir
Specifies the local directory where a separate log file is created for each tunnel client.When this property is not empty, files are named using the pattern
tunnel_client_log_{random_id}.txt.- Returns:
- the value of the
ClientLogDirproperty
-
setClientLogDir
Sets theClientLogDirproperty; seegetClientLogDir().- Parameters:
value- the new value (notnull)
-
getConnectTimeoutMs
public int getConnectTimeoutMs()Specifies the maximum number of milliseconds allowed for establishing the SSH connection.- The default value is
30000milliseconds (30 seconds). - A value of
0disables the connection timeout and allows an unlimited wait.
The timeout applies to more than the initial TCP connection. It also covers connection setup performed through an HTTP or SOCKS proxy and waiting for the SSH server identification string after the TCP connection has been established.
- Returns:
- the value of the
ConnectTimeoutMsproperty
- The default value is
-
setConnectTimeoutMs
public void setConnectTimeoutMs(int value)Sets theConnectTimeoutMsproperty; seegetConnectTimeoutMs().- Parameters:
value- the new value
-
getDestHostname
Specifies the destination hostname or IP address for fixed-destination port forwarding. This is typically the host running the database server or other TCP service that local clients need to reach.The destination is interpreted from the SSH server's network environment. For example,
localhostand127.0.0.1refer to the SSH server itself, not the computer running the application. Hostname resolution is therefore performed as part of the forwarding request on the SSH-server side.Traffic accepted by the local listener is carried through SSH, forwarded by the SSH server to this destination, and returned through the same tunnel.
This property is ignored when
isgetDynamicPortForwarding(). Changing the destination while the listener is running affects new clients only; existing clients remain connected to the destination selected when they were accepted.true- Returns:
- the value of the
DestHostnameproperty
-
setDestHostname
Sets theDestHostnameproperty; seegetDestHostname().- Parameters:
value- the new value (notnull)
-
getDestPort
public int getDestPort()Specifies the TCP port of the destination service used for fixed-destination forwarding, such as the port of a database server.It is used together with
and is ignored whengetDestHostname()isgetDynamicPortForwarding().true- Returns:
- the value of the
DestPortproperty
-
setDestPort
public void setDestPort(int value)Sets theDestPortproperty; seegetDestPort().- Parameters:
value- the new value
-
getDynamicPortForwarding
public boolean getDynamicPortForwarding()Controls whether the listener performs fixed-destination or dynamic port forwarding.-
When
(the default), every accepted connection is forwarded tofalseandgetDestHostname().getDestPort() -
When
, the listener acts as a SOCKS proxy and each inbound client supplies its own destination.true
The SOCKS version is detected independently from each inbound client handshake; there is no separate inbound SOCKS-version property. SOCKS4 and SOCKS5
CONNECTrequests are supported. SOCKS5BINDand UDP association are not supported.Leave
empty to allow SOCKS5 clients to use the no-authentication method. Set the inbound username and password to require SOCKS5 username/password authentication. For SOCKS4, only the user ID can be checked because SOCKS4 has no password field.getInboundSocksUsername()SOCKS4a hostname-form requests are not supported. Use a numeric IPv4 address with SOCKS4, or use SOCKS5 when the client needs to supply a domain name.
- Returns:
- the value of the
DynamicPortForwardingproperty
-
When
-
setDynamicPortForwarding
public void setDynamicPortForwarding(boolean value)Sets theDynamicPortForwardingproperty; seegetDynamicPortForwarding().- Parameters:
value- the new value
-
getEnableSecrets
public boolean getEnableSecrets()Enables automatic resolution of credentials from secure storage provided by the operating system.When set to
, supported password properties and methods may receive a secret specification string beginning withtrue!!instead of a literal password. Chilkat resolves the secret from:- Windows Credential Manager on Windows.
- Apple Keychain on macOS.
The specification format is:
!![appName|]service[|domain]|usernameThis applies to
,getHttpProxyPassword(),getSocksPassword(), andauthenticatePw(String, String).authenticatePwPk(String, String, SshKey)The default value is
.false- Returns:
- the value of the
EnableSecretsproperty
-
setEnableSecrets
public void setEnableSecrets(boolean value)Sets theEnableSecretsproperty; seegetEnableSecrets().- Parameters:
value- the new value
-
getHostKeyFingerprint
Contains the SSH server host-key fingerprint afterorconnect(String, int)establishes the SSH connection. The value is available before user authentication.connectThroughSsh(Ssh, String, int)Example:
ssh-ed25519 256 e0:33:b1:81:a5:c6:9a:d2:2e:c9:d3:15:60:ea:cf:4cCompare this value with a trusted expected fingerprint to verify the identity of the SSH server. For
, the fingerprint is for the final SSH server, not the first-hop server.connectThroughSsh(Ssh, String, int)The value may remain populated after
or after the connection is lost. UsecloseTunnel(boolean)to determine current connection state.isSshConnected()- Returns:
- the value of the
HostKeyFingerprintproperty (read-only)
-
getHttpProxyAuthMethod
Specifies the authentication method to use when the outbound connection to the SSH server passes through an HTTP proxy that requires authentication.Valid values are
BasicandNTLM.If
is set togetSocksVersion()4or5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.- Returns:
- the value of the
HttpProxyAuthMethodproperty
-
setHttpProxyAuthMethod
Sets theHttpProxyAuthMethodproperty; seegetHttpProxyAuthMethod().- Parameters:
value- the new value (notnull)
-
getHttpProxyDomain
Specifies the optional Windows domain used for NTLM authentication with the HTTP proxy.This applies only to the outbound proxy connection used to reach the SSH server, and only when
isgetHttpProxyAuthMethod()NTLM.If
is set togetSocksVersion()4or5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.- Returns:
- the value of the
HttpProxyDomainproperty
-
setHttpProxyDomain
Sets theHttpProxyDomainproperty; seegetHttpProxyDomain().- Parameters:
value- the new value (notnull)
-
getHttpProxyHostname
Specifies the hostname or IPv4 address of the HTTP proxy through which the outbound connection to the SSH server is made.Leave this property empty when no HTTP proxy is required.
If
is set togetSocksVersion()4or5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.- Returns:
- the value of the
HttpProxyHostnameproperty
-
setHttpProxyHostname
Sets theHttpProxyHostnameproperty; seegetHttpProxyHostname().- Parameters:
value- the new value (notnull)
-
getHttpProxyPassword
Specifies the password used to authenticate with the HTTP proxy for the outbound connection to the SSH server.If
is set togetSocksVersion()4or5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.- Returns:
- the value of the
HttpProxyPasswordproperty
-
setHttpProxyPassword
Sets theHttpProxyPasswordproperty; seegetHttpProxyPassword().- Parameters:
value- the new value (notnull)
-
getHttpProxyPort
public int getHttpProxyPort()Specifies the TCP port of the HTTP proxy used for the outbound connection to the SSH server.Common HTTP proxy ports include
8080and3128.If
is set togetSocksVersion()4or5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.- Returns:
- the value of the
HttpProxyPortproperty
-
setHttpProxyPort
public void setHttpProxyPort(int value)Sets theHttpProxyPortproperty; seegetHttpProxyPort().- Parameters:
value- the new value
-
getHttpProxyUsername
Specifies the username used to authenticate with the HTTP proxy for the outbound connection to the SSH server.If
is set togetSocksVersion()4or5, the SOCKS proxy takes precedence and these HTTP proxy settings are ignored. The proxies are not chained.- Returns:
- the value of the
HttpProxyUsernameproperty
-
setHttpProxyUsername
Sets theHttpProxyUsernameproperty; seegetHttpProxyUsername().- Parameters:
value- the new value (notnull)
-
getIdleTimeoutMs
public int getIdleTimeoutMs()Specifies a stall timeout, in milliseconds, for tunnel data-transfer operations. The default value is30000milliseconds (30 seconds). A value of0disables the timeout.This property is not a general inactivity timer for established background tunnel clients. An otherwise idle client, or a client with data queued while an SSH channel is flow-controlled, may remain connected beyond this interval. Applications should not rely on this property to disconnect clients merely because no application data is flowing.
- Returns:
- the value of the
IdleTimeoutMsproperty
-
setIdleTimeoutMs
public void setIdleTimeoutMs(int value)Sets theIdleTimeoutMsproperty; seegetIdleTimeoutMs().- Parameters:
value- the new value
-
getInboundSocksPassword
Specifies the password required from inbound SOCKS5 clients whenisgetDynamicPortForwarding().trueThis property is used together with
. It does not apply to SOCKS4 because the SOCKS4 protocol has no password field.getInboundSocksUsername()- Returns:
- the value of the
InboundSocksPasswordproperty
-
setInboundSocksPassword
Sets theInboundSocksPasswordproperty; seegetInboundSocksPassword().- Parameters:
value- the new value (notnull)
-
getInboundSocksUsername
Specifies the username required from inbound SOCKS clients whenisgetDynamicPortForwarding().true- For SOCKS5, setting this property enables username/password authentication.
- For SOCKS4, the value is compared with the client-supplied user ID.
- Leave it empty to require no inbound SOCKS username.
- Returns:
- the value of the
InboundSocksUsernameproperty
-
setInboundSocksUsername
Sets theInboundSocksUsernameproperty; seegetInboundSocksUsername().- Parameters:
value- the new value (notnull)
-
getIsAccepting
public boolean getIsAccepting()when the local listener thread is running and accepting inbound TCP connections; otherwisetrue.falseThis property describes only the local listener. It can remain
after the SSH connection is lost or aftertrueis called. In those states a client may connect to the local port even though its traffic cannot be forwarded.closeTunnel(boolean)Use
separately when the application also needs to know whether the SSH transport is available.isSshConnected()- Returns:
- the value of the
IsAcceptingproperty (read-only)
-
getKeepAcceptLog
public boolean getKeepAcceptLog()Controls whether activity from the background listener thread is retained in memory.The default value is
. When enabled, retrieve the log fromfalse.getAcceptLog()- Returns:
- the value of the
KeepAcceptLogproperty
-
setKeepAcceptLog
public void setKeepAcceptLog(boolean value)Sets theKeepAcceptLogproperty; seegetKeepAcceptLog().- Parameters:
value- the new value
-
getKeepTunnelLog
public boolean getKeepTunnelLog()Controls whether SSH tunnel-thread activity is retained in memory.The default value is
. When enabled, retrieve the log fromfalse.getTunnelLog()- Returns:
- the value of the
KeepTunnelLogproperty
-
setKeepTunnelLog
public void setKeepTunnelLog(boolean value)Sets theKeepTunnelLogproperty; seegetKeepTunnelLog().- Parameters:
value- the new value
-
getListenBindIpAddress
Specifies the local IPv4 address to which the tunnel's listening socket is bound.Value Listener exposure
Empty string Binds to
0.0.0.0and accepts connections on all local IPv4 interfaces, subject to firewall rules.127.0.0.1Accepts connections only from the local computer through loopback.A specific local LAN address Accepts connections through that interface only; loopback is not included automatically.
For a tunnel intended only for local applications, explicitly set this property to
127.0.0.1. Leaving it empty may expose the listening port to other computers on the network.If the value is malformed or is not assigned to a local interface,
returnsbeginAccepting(int)and the bind failure is available infalseLastErrorTextand the accept log.- Returns:
- the value of the
ListenBindIpAddressproperty
-
setListenBindIpAddress
Sets theListenBindIpAddressproperty; seegetListenBindIpAddress().- Parameters:
value- the new value (notnull)
-
getListenPort
public int getListenPort()Contains the local TCP port used by the listener started by.beginAccepting(int)-
If
BeginAcceptingsucceeds with a nonzero requested port, this property contains that port. -
If
BeginAcceptingsucceeds with0, the operating system chooses an available port and this property contains the allocated port when the method returns. -
After a bind failure for an explicitly requested port, this property may still
contain the requested port even though
isgetIsAccepting().false - The value is initially
0.
- Returns:
- the value of the
ListenPortproperty (read-only)
-
If
-
getOutboundBindIpAddress
Specifies the local IP address to which the outbound socket is bound before connecting to the SSH server.Most applications should leave this property empty. Set it only on a multihomed computer when the SSH connection must originate from a specific local network interface or IP address.
- Returns:
- the value of the
OutboundBindIpAddressproperty
-
setOutboundBindIpAddress
Sets theOutboundBindIpAddressproperty; seegetOutboundBindIpAddress().- Parameters:
value- the new value (notnull)
-
getOutboundBindPort
public int getOutboundBindPort()Specifies the local TCP port to bind before making the outbound connection to the SSH server.The default value is
0, which allows the operating system to choose an available ephemeral port. Nearly all applications should leave this property unchanged.- Returns:
- the value of the
OutboundBindPortproperty
-
setOutboundBindPort
public void setOutboundBindPort(int value)Sets theOutboundBindPortproperty; seegetOutboundBindPort().- Parameters:
value- the new value
-
getPreferIpv6
public boolean getPreferIpv6()Controls which IP version is preferred when a hostname resolves to both IPv4 and IPv6 addresses.(the default) prefers IPv4.falseprefers IPv6.true
- Returns:
- the value of the
PreferIpv6property
-
setPreferIpv6
public void setPreferIpv6(boolean value)Sets thePreferIpv6property; seegetPreferIpv6().- Parameters:
value- the new value
-
getSoRcvBuf
public int getSoRcvBuf()Sets the receive-buffer size for the underlying TCP socket.The default value is
4194304bytes. Normally this property should remain unchanged. If receive performance is unusually slow, testing a larger value that is a multiple of4096may help.- Returns:
- the value of the
SoRcvBufproperty
-
setSoRcvBuf
public void setSoRcvBuf(int value)Sets theSoRcvBufproperty; seegetSoRcvBuf().- Parameters:
value- the new value
-
getSoSndBuf
public int getSoSndBuf()Sets the send-buffer size for the underlying TCP socket.The default value is
262144bytes. Normally this property should remain unchanged. If send performance is unusually slow, testing values such as524288or1048576may help. A multiple of4096is recommended.- Returns:
- the value of the
SoSndBufproperty
-
setSoSndBuf
public void setSoSndBuf(int value)Sets theSoSndBufproperty; seegetSoSndBuf().- Parameters:
value- the new value
-
getSocksHostname
Specifies the hostname or IPv4 address of the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.This property is used only when
isgetSocksVersion()4or5.- Returns:
- the value of the
SocksHostnameproperty
-
setSocksHostname
Sets theSocksHostnameproperty; seegetSocksHostname().- Parameters:
value- the new value (notnull)
-
getSocksPassword
Specifies the password for authenticating with an outbound SOCKS5 proxy used to reach the SSH server.SOCKS4 does not support password authentication, so this property does not apply when
isgetSocksVersion()4.- Returns:
- the value of the
SocksPasswordproperty
-
setSocksPassword
Sets theSocksPasswordproperty; seegetSocksPassword().- Parameters:
value- the new value (notnull)
-
getSocksPort
public int getSocksPort()Specifies the TCP port of the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.The default value is
1080. This property is used only whenisgetSocksVersion()4or5.- Returns:
- the value of the
SocksPortproperty
-
setSocksPort
public void setSocksPort(int value)Sets theSocksPortproperty; seegetSocksPort().- Parameters:
value- the new value
-
getSocksUsername
Specifies the username for the outbound SOCKS4 or SOCKS5 proxy used to reach the SSH server.This property is used only when
isgetSocksVersion()4or5.- Returns:
- the value of the
SocksUsernameproperty
-
setSocksUsername
Sets theSocksUsernameproperty; seegetSocksUsername().- Parameters:
value- the new value (notnull)
-
getSocksVersion
public int getSocksVersion()Selects whether the outbound connection to the SSH server is made through a SOCKS proxy.Value Behavior
0Do not use a SOCKS proxy. This is the default.4Connect through a SOCKS4 proxy.5Connect through a SOCKS5 proxy.When this property is
4or5, the SOCKS proxy settings take precedence over the HTTP proxy settings. The SOCKS and HTTP proxies are not chained.- Returns:
- the value of the
SocksVersionproperty
-
setSocksVersion
public void setSocksVersion(int value)Sets theSocksVersionproperty; seegetSocksVersion().- Parameters:
value- the new value
-
getTcpNoDelay
public boolean getTcpNoDelay()Controls theTCP_NODELAYsocket option for the underlying TCP connection.The default value is
. Setting it tofalsedisables the Nagle algorithm, which can reduce latency when many small amounts of data are sent.true- Returns:
- the value of the
TcpNoDelayproperty
-
setTcpNoDelay
public void setTcpNoDelay(boolean value)Sets theTcpNoDelayproperty; seegetTcpNoDelay().- Parameters:
value- the new value
-
getTunnelLog
Contains the in-memory activity log for the SSH tunnel and client-manager threads. The log is populated only whenisgetKeepTunnelLog().trueTreat this log as sensitive diagnostic data. It can contain hostnames, ports, usernames, proxy details, SOCKS handshake information, and authentication failure values. Do not publish or persist it without reviewing and protecting its contents.
- Returns:
- the value of the
TunnelLogproperty
-
setTunnelLog
Sets theTunnelLogproperty; seegetTunnelLog().- Parameters:
value- the new value (notnull)
-
getTunnelLogPath
Specifies the local file path where SSH tunnel-thread activity is written.This file-based log is separate from the in-memory
.getTunnelLog()- Returns:
- the value of the
TunnelLogPathproperty
-
setTunnelLogPath
Sets theTunnelLogPathproperty; seegetTunnelLogPath().- Parameters:
value- the new value (notnull)
-
getUncommonOptions
Provides optional behavior for uncommon requirements. The default value is an empty string, which is appropriate for most applications.To enable more than one option, provide a comma-separated list of keywords.
Keyword Effect
ForceUserAuthRsaSha1Forcesrsa-sha1for public-key user authentication. Set this before connecting. Added in v9.5.0.98.NoKeepAliveIgnoreMsgDisables the default SSHignoremessage sent every 20 seconds to keep an idle connection alive. Added in v9.5.0.76.no-weak-mac-algsRemoveshmac-sha1-96,hmac-sha1,hmac-md5, andhmac-ripemd160from the offered MAC algorithms. Added in v9.5.0.98.ProtectFromVpnOn Android, bypasses an installed or active VPN. Added in v9.5.0.80.+ssh-hmac-etmRe-enables SSH encrypt-then-MAC algorithms that were disabled by default in v9.5.0.97 as part of the Terrapin mitigation.+chacha20-poly1305@openssh.comRe-enableschacha20-poly1305@openssh.com, which was removed from the default offer in v9.5.0.97 as part of the Terrapin mitigation.- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
authenticatePk
Authenticates with the SSH server using public-key authentication.The public key corresponding to
privateKeymust already be installed forusernameon the SSH server.Call
orconnect(String, int)before calling this method.connectThroughSsh(Ssh, String, int)When requesting support for an authentication failure, include the complete
LastErrorText.- Parameters:
username- theusernameargument (notnull)privateKey- theprivateKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
authenticatePw
Authenticates with the SSH server usingloginandpassword.Establish the SSH connection first by calling
orconnect(String, int). After authentication succeeds, callconnectThroughSsh(Ssh, String, int)to begin accepting tunnel clients.beginAccepting(int)- A rejected username or password does not close the SSH connection; the application may correct the credentials and call this method again.
- Calling this method again after authentication has already succeeded returns
with an “Already authenticated” error.false
When requesting support for an authentication failure, include the complete
LastErrorTextcaptured immediately after the failed call.- Parameters:
login- theloginargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
authenticatePwPk
Authenticates with an SSH server that requires both a password and a private key.The public key corresponding to
privateKeymust already be installed forusernameon the SSH server. Most SSH servers require either password authentication or public-key authentication rather than both.When requesting support for an authentication failure, include the complete
LastErrorText.- Parameters:
username- theusernameargument (notnull)password- thepasswordargument (notnull)privateKey- theprivateKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
authenticateSecPw
Performs the same password authentication as, but receives the login and password inauthenticatePw(String, String)SecureStringobjects.- Parameters:
login- theloginargument (notnull)password- thepasswordargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
authenticateSecPwPk
Performs the same combined password-and-private-key authentication as, but receives the username and password inauthenticatePwPk(String, String, SshKey)SecureStringobjects.- Parameters:
username- theusernameargument (notnull)password- thepasswordargument (notnull)privateKey- theprivateKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
beginAccepting
public void beginAccepting(int listenPort)Creates and starts the local listener onlistenPort.The SSH connection must already have been established. Although the listener can be started before user authentication, clients accepted in that state cannot be forwarded. The recommended sequence is to connect, authenticate, and then call this method.
- The requested port must not already be in use on the selected local interface.
- Pass
0to let the operating system choose an available port, then read.getListenPort() - Calling this method while the listener is already running returns
.false
The method waits for the initial bind-and-listen result. It returns
for errors such as an occupied port, a malformed bind address, or an address that is not assigned to the local computer. Details are available immediately infalseLastErrorTextand, when enabled, the accept log.A successful return means the listener was bound and started. No additional fixed delay is required merely to discover an initial bind failure.
- Parameters:
listenPort- thelistenPortargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
closeTunnel
public void closeTunnel(boolean waitForThreads)Disconnects active tunnel clients and stops the tunnel-manager thread.When
waitForThreadsis, the method waits for the client and tunnel-manager threads to exit. It returnstrueif a worker thread does not stop; capturefalseLastErrorTextimmediately for details.This method does not stop the local listener and does not disconnect or reset the underlying SSH transport. Call
separately to stop accepting local TCP connections. After this method returns, the listener may still accept a local connection even though the connection cannot be forwarded.stopAccepting(boolean)Calling this method more than once is allowed. However, it does not reset the object for a new call to
. Use a newconnect(String, int)SshTunnelobject when connecting to a different SSH server.- Parameters:
waitForThreads- thewaitForThreadsargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
connect
Establishes the SSH connection that will carry tunneled traffic. This method performs the TCP or proxy connection, the SSH protocol handshake, and host-key negotiation, but it does not authenticate the SSH user.After connecting, verify
, then authenticate by calling one of thegetHostKeyFingerprint()Authenticate*methods. Finally, callto start the local listener.beginAccepting(int)The host-key fingerprint is available immediately after this method succeeds, before user authentication. Calling
Connectagain while an SSH tunnel already exists returns.falseChilkat sends an SSH
ignoremessage every 20 seconds to help keep an unused SSH connection alive. To disable this behavior, addNoKeepAliveIgnoreMsgtobefore connecting.getUncommonOptions()- Parameters:
hostname- thehostnameargument (notnull)port- theportargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
connectThroughSsh
Connects to a second SSH server through the existing connected and authenticatedSshobject supplied inssh.application -> first SSH server -> second SSH server
hostnameandportidentify the second SSH server. After this method succeeds, call an authentication method on thisSshTunnelobject to authenticate with the second server.The supplied
Sshobject is borrowed, not copied. It must remain alive, connected, and authenticated for as long as this tunnel is used. If the first-hop object is disconnected, existing forwarded clients stop working and new local connections cannot be forwarded. The local listener may nevertheless remain active until explicitly stopped.reports the fingerprint of the second SSH server. After the connection is established, fixed forwarding destinations such asgetHostKeyFingerprint()127.0.0.1are interpreted from the second server's network environment.- Parameters:
ssh- thesshargument (notnull)hostname- thehostnameargument (notnull)port- theportargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
continueKeyboardAuth
Continues a keyboard-interactive authentication exchange started by.startKeyboardAuth(String)If the server requested one response, pass that value directly in
response. If it requested multiple responses, pass XML in the following form:_LT_response_GT_ _LT_response1_GT_response to first prompt_LT_/response1_GT_ _LT_response2_GT_response to second prompt_LT_/response2_GT_ ... _LT_responseN_GT_response to Nth prompt_LT_/responseN_GT_ _LT_/response_GT_
When authentication completes, the returned XML indicates success or failure:
_LT_success_GT_success message_LT_/success_GT_ _LT_error_GT_error message_LT_/error_GT_
If another challenge is required, the method returns another
infoRequestXML document containing the next set of prompts.- Parameters:
response- theresponseargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
disconnectAllClients
public void disconnectAllClients(boolean waitForThreads)Disconnects all active tunnel clients while leaving the local listener and SSH connection available.When
waitForThreadsis, the method waits for the current client threads to exit before returning. The listener continues accepting new clients, and newly accepted clients can be forwarded normally.true- Parameters:
waitForThreads- thewaitForThreadsargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getCurrentState
Returns an XML snapshot describing the tunnel manager, SSH channels, and current tunnel clients. The returned data is intended for diagnostics and monitoring.A typical result has the following structure:
_LT_CurrentState_GT_ _LT_tunnelManager rcvByteCount="433" sndByteCount="34" threadRunning="1" dynamicPortForwarding="0" staticDestHost="localhost" staticDestPort="18080"_GT_ _LT_openChannels count="1"_GT_ _LT_channel num="101" channelType="direct-tcpip" clientWinSize="2096927" serverWinSize="2097127" /_GT_ _LT_/openChannels_GT_ _LT_closedChannels count="0" /_GT_ _LT_/tunnelManager_GT_ _LT_clients count="1"_GT_ _LT_client destIp="localhost" destPort="18080" sshChannelNum="101" threadRunning="1" rcvByteCount="25" sndByteCount="225" /_GT_ _LT_/clients_GT_ _LT_/CurrentState_GT_The exact child elements can vary with state. For example, channel collections may be empty, and some transport details may be omitted before the tunnel is started or after it stops.
Section Information
tunnelManagerAggregate byte counts, worker-thread state, forwarding mode, and configured fixed destination.openChannelsandclosedChannelsSSH channel numbers, close/EOF flags, packet sizes, and flow-control window sizes.clientsPer-client destination, SSH channel number, worker state, age/activity counters, pending-data flags, and byte counts.- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
isSshConnected
public boolean isSshConnected()Returnswhen the SSH transport used by this tunnel is connected; otherwise returnstrue.falseThis is independent of the local listener state. The listener may still be accepting local TCP connections when this method returns
, but those connections cannot be forwarded until a usable SSH transport exists.falseFor a tunnel created with
, this method becomesconnectThroughSsh(Ssh, String, int)when the borrowed first-hopfalseSshconnection is disconnected.- Returns:
- the result; this method never throws
ChilkatException
-
setAllowedAlgorithms
Restricts the SSH connection to the algorithms specified injson.This allows an application to define the exact algorithm set that may be used during SSH negotiation.
- Parameters:
json- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
startKeyboardAuth
Begins keyboard-interactive authentication forlogin.When the server requests one or more responses, the returned XML contains the request name, instructions, and prompts:
_LT_infoRequest numPrompts="N"_GT_ _LT_name_GT_name text_LT_/name_GT_ _LT_instruction_GT_instruction text_LT_/instruction_GT_ _LT_prompt1 echo="1_or_0"_GT_prompt text_LT_/prompt1_GT_ ... _LT_promptN echo="1_or_0"_GT_prompt text_LT_/promptN_GT_ _LT_/infoRequest_GT_
The
echoattribute indicates whether the response should be displayed while entered.If authentication immediately succeeds or fails without requiring a response, the returned XML has one of these forms:
_LT_success_GT_success message_LT_/success_GT_ _LT_error_GT_error message_LT_/error_GT_
Pass the requested response or responses to
.continueKeyboardAuth(String)- Parameters:
login- theloginargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
stopAccepting
public void stopAccepting(boolean waitForThread)Stops the local listener so that no new client connections are accepted. Existing forwarded clients remain connected and continue exchanging data.- When
waitForThreadis, the method waits for the listener thread to exit before returning.true - When it is
, shutdown is asynchronous andfalsemay remaingetIsAccepting()briefly after the method returns.true
Call
again to resume accepting connections. The listener can be restarted on the same port after the previous listener has stopped.beginAccepting(int)- Parameters:
waitForThread- thewaitForThreadargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
- When
-
setProgressListener
Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.- Parameters:
listener- the listener, ornull- Throws:
IllegalStateException- if called from inside one of this object's own callbacks
-
getProgressListener
Returns the installed listener, ornull.- Returns:
- the listener installed with
setProgressListener(ProgressListener)or one of theon...methods
-
onAbortCheck
Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onPercentDone
Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onProgressInfo
Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-