PowerBuilder
PowerBuilder
Open an SSH Tunnel
See more Socket/SSL/TLS Examples
Demonstrates Socket.SshOpenTunnel, which connects to an SSH server and initializes an SSH tunneling session, then authenticates it.
Background. An SSH tunnel lets a socket reach a destination host through an SSH server using port forwarding. The sequence is: open the tunnel, authenticate, then open forwarded channels to destinations.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Socket
string ls_SshPassword
li_Success = 0
loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
destroy loo_Socket
MessageBox("Error","Connecting to COM object failed")
return
end if
// Connect to the SSH server and initialize an SSH tunneling session. Port 22 is conventional but
// not required.
li_Success = loo_Socket.SshOpenTunnel("ssh.example.com",22)
if li_Success = 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
return
end if
// After the tunnel is open, authenticate before opening forwarded channels.
// The SSH password should come from a secure source rather than being hard-coded.
ls_SshPassword = "mySshPassword"
li_Success = loo_Socket.SshAuthenticatePw("sshUser",ls_SshPassword)
if li_Success = 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
return
end if
Write-Debug "SSH tunnel established and authenticated."
destroy loo_Socket