AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Demonstrates the SshTunnel connection-behavior properties ConnectTimeoutMs, IdleTimeoutMs, and
; PreferIpv6.
$oTunnel = ObjCreate("Chilkat.SshTunnel")
; Maximum time to establish the SSH connection (default 30000 ms).
$oTunnel.ConnectTimeoutMs = 10000
; Stall timeout for tunnel data-transfer operations (default 30000 ms).
$oTunnel.IdleTimeoutMs = 15000
; When a hostname resolves to both IPv4 and IPv6, prefer IPv6. The default (False) prefers IPv4.
$oTunnel.PreferIpv6 = True
$oTunnel.DestHostname = "db.internal.example.com"
$oTunnel.DestPort = 5432
Local $iSshPort = 22
$bSuccess = $oTunnel.Connect("ssh.example.com",$iSshPort)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
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.
Local $sPassword = "mySshPassword"
$bSuccess = $oTunnel.AuthenticatePw("mySshLogin",$sPassword)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf
Local $iListenPort = 1080
$bSuccess = $oTunnel.BeginAccepting($iListenPort)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Tunnel established." & @CRLF)
Local $bWaitForThreadExit = True
$bSuccess = $oTunnel.CloseTunnel($bWaitForThreadExit)
If ($bSuccess = False) Then
ConsoleWrite($oTunnel.LastErrorText & @CRLF)
Exit
EndIf