PowerBuilder
PowerBuilder
SSH Tunnel Listener Activity Log
See more SSH Tunnel Examples
Demonstrates the listener-log properties KeepAcceptLog, AcceptLog, and AcceptLogPath, which record the activity of the background listener thread started by BeginAccepting.
Note: The log paths are relative to the application's current working directory. Absolute paths may also be used.
Background: Because the listener runs on a background thread, an activity log is often the only practical way to see what it is doing — which connections it accepted and when.
KeepAcceptLog must be enabled for the in-memory AcceptLog to be populated; AcceptLogPath is an independent file-based log that persists across the run. This log covers the listener specifically, as distinct from the TunnelLog that records the SSH tunnel threads.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Tunnel
integer li_SshPort
string ls_Password
integer li_ListenPort
integer li_WaitForThreadExit
li_Success = 0
// Demonstrates the SshTunnel listener-log properties KeepAcceptLog, AcceptLog, and AcceptLogPath.
//
// These log the activity of the background listener thread started by BeginAccepting.
loo_Tunnel = create oleobject
li_rc = loo_Tunnel.ConnectToNewObject("Chilkat.SshTunnel")
if li_rc < 0 then
destroy loo_Tunnel
MessageBox("Error","Connecting to COM object failed")
return
end if
// Retain the listener activity log in memory so it can be read from the AcceptLog property.
loo_Tunnel.KeepAcceptLog = 1
// Optionally also write the listener activity to a file (separate from the in-memory log).
loo_Tunnel.AcceptLogPath = "qa_output/accept.log"
loo_Tunnel.DestHostname = "db.internal.example.com"
loo_Tunnel.DestPort = 5432
li_SshPort = 22
li_Success = loo_Tunnel.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
// 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.
ls_Password = "mySshPassword"
li_Success = loo_Tunnel.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
li_ListenPort = 1080
li_Success = loo_Tunnel.BeginAccepting(li_ListenPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
// ... the listener accepts connections for a while ...
// Read the accumulated in-memory listener log.
Write-Debug loo_Tunnel.AcceptLog
li_WaitForThreadExit = 1
li_Success = loo_Tunnel.CloseTunnel(li_WaitForThreadExit)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
destroy loo_Tunnel