Sample code for 30+ languages & platforms
PowerBuilder

Close an SSH Tunnel

See more Socket/SSL/TLS Examples

Demonstrates Socket.SshCloseTunnel, which closes the SSH tunnel opened by SshOpenTunnel and terminates its forwarded channels.

Background. Closing the tunnel does not affect unrelated SSH objects or connections.

Chilkat PowerBuilder Downloads

PowerBuilder
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

//  Authenticate the SSH session 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

//  Close the SSH tunnel and terminate its forwarded channels.  This does not affect unrelated SSH
//  objects or connections.
li_Success = loo_Socket.SshCloseTunnel()
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

Write-Debug "SSH tunnel closed."


destroy loo_Socket