Sample code for 30+ languages & platforms
Lianja

SSH Tunnel Uncommon Options

See more SSH Tunnel Examples

Demonstrates the UncommonOptions property, which enables optional behavior for uncommon requirements. The default is an empty string; provide a comma-separated list of keywords to enable more than one option. Available keywords are listed in the reference documentation.

Background: This is a catch-all for narrow workarounds that do not warrant their own properties — forcing a specific signature algorithm, disabling the periodic keep-alive, removing weak MACs, bypassing a VPN on Android, and so on. Most applications never set it. When you do, it is usually to satisfy a particular server's quirk or a specific security requirement, and the exact keyword matters, so consult the documented list rather than guessing.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

//  Demonstrates the SshTunnel.UncommonOptions property, which enables optional behavior for
//  uncommon requirements.  The default is an empty string, appropriate for most applications.
//  Provide a comma-separated list of keywords to enable more than one option.

loTunnel = createobject("CkSshTunnel")

//  For example, disable the periodic keep-alive ignore message and remove weak MAC algorithms
//  from those offered.  Available keywords are listed in the reference documentation.
loTunnel.UncommonOptions = "NoKeepAliveIgnoreMsg,no-weak-mac-algs"

loTunnel.DestHostname = "db.internal.example.com"
loTunnel.DestPort = 5432

lnSshPort = 22
llSuccess = loTunnel.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif

//  Normally you would not hard-code the password in source.  You should instead obtain it
//  from an interactive prompt, environment variable, or a secrets vault.
lcPassword = "mySshPassword"

llSuccess = loTunnel.AuthenticatePw("mySshLogin",lcPassword)
if (llSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif

lnListenPort = 1080
llSuccess = loTunnel.BeginAccepting(lnListenPort)
if (llSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif

? "Tunnel established."

llWaitForThreadExit = .T.
llSuccess = loTunnel.CloseTunnel(llWaitForThreadExit)
if (llSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif



release loTunnel