Visual FoxPro
Visual FoxPro
SSH Tunnel Timeouts and IP Preference
See more SSH Tunnel Examples
Demonstrates the ConnectTimeoutMs, IdleTimeoutMs, and PreferIpv6 properties, which govern how long the tunnel waits to connect and to transfer data, and which IP version it prefers.
Background:
ConnectTimeoutMs bounds how long a connection attempt blocks — important so an unreachable server fails promptly instead of hanging — while IdleTimeoutMs guards against a stalled transfer holding a connection open indefinitely. PreferIpv6 only matters when a hostname resolves to both address families, choosing which to try first; the default prefers IPv4.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loTunnel
LOCAL lnSshPort
LOCAL lcPassword
LOCAL lnListenPort
LOCAL lnWaitForThreadExit
lnSuccess = 0
* Demonstrates the SshTunnel connection-behavior properties ConnectTimeoutMs, IdleTimeoutMs, and
* PreferIpv6.
loTunnel = CreateObject('Chilkat.SshTunnel')
* Maximum time to establish the SSH connection (default 30000 ms).
loTunnel.ConnectTimeoutMs = 10000
* Stall timeout for tunnel data-transfer operations (default 30000 ms).
loTunnel.IdleTimeoutMs = 15000
* When a hostname resolves to both IPv4 and IPv6, prefer IPv6. The default (0) prefers IPv4.
loTunnel.PreferIpv6 = 1
loTunnel.DestHostname = "db.internal.example.com"
loTunnel.DestPort = 5432
lnSshPort = 22
lnSuccess = loTunnel.Connect("ssh.example.com",lnSshPort)
IF (lnSuccess = 0) THEN
? loTunnel.LastErrorText
RELEASE loTunnel
CANCEL
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"
lnSuccess = loTunnel.AuthenticatePw("mySshLogin",lcPassword)
IF (lnSuccess = 0) THEN
? loTunnel.LastErrorText
RELEASE loTunnel
CANCEL
ENDIF
lnListenPort = 1080
lnSuccess = loTunnel.BeginAccepting(lnListenPort)
IF (lnSuccess = 0) THEN
? loTunnel.LastErrorText
RELEASE loTunnel
CANCEL
ENDIF
? "Tunnel established."
lnWaitForThreadExit = 1
lnSuccess = loTunnel.CloseTunnel(lnWaitForThreadExit)
IF (lnSuccess = 0) THEN
? loTunnel.LastErrorText
RELEASE loTunnel
CANCEL
ENDIF
RELEASE loTunnel