DataFlex
DataFlex
SSH Tunnel Thread Activity Log
See more SSH Tunnel Examples
Demonstrates the tunnel-log properties KeepTunnelLog, TunnelLog, and TunnelLogPath, which record the activity of the SSH tunnel and client-manager threads.
Note: The log paths are relative to the application's current working directory. Absolute paths may also be used.
Background: This is the counterpart to the accept log, covering the SSH side rather than the listener: the tunnel and client-manager threads that actually move data. As with the accept log,
KeepTunnelLog enables the in-memory TunnelLog while TunnelLogPath writes a separate file. Together the two logs let you localize a problem to either the accepting side or the forwarding side.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTunnel
Integer iSshPort
String sPassword
Integer iListenPort
Boolean iWaitForThreadExit
String sTemp1
Move False To iSuccess
// Demonstrates the SshTunnel tunnel-log properties KeepTunnelLog, TunnelLog, and TunnelLogPath.
//
// These log the activity of the SSH tunnel and client-manager threads.
Get Create (RefClass(cComChilkatSshTunnel)) To hoTunnel
If (Not(IsComObjectCreated(hoTunnel))) Begin
Send CreateComObject of hoTunnel
End
// Retain the SSH tunnel-thread activity in memory so it can be read from the TunnelLog property.
Set ComKeepTunnelLog Of hoTunnel To True
// Optionally also write the tunnel-thread activity to a file (separate from the in-memory log).
Set ComTunnelLogPath Of hoTunnel To "qa_output/tunnel.log"
Set ComDestHostname Of hoTunnel To "db.internal.example.com"
Set ComDestPort Of hoTunnel To 5432
Move 22 To iSshPort
Get ComConnect Of hoTunnel "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Move "mySshPassword" To sPassword
Get ComAuthenticatePw Of hoTunnel "mySshLogin" sPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Move 1080 To iListenPort
Get ComBeginAccepting Of hoTunnel iListenPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
// ... clients transfer data through the tunnel ...
// Read the accumulated in-memory tunnel log.
Get ComTunnelLog Of hoTunnel To sTemp1
Showln sTemp1
Move True To iWaitForThreadExit
Get ComCloseTunnel Of hoTunnel iWaitForThreadExit To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure