DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
String sSshPassword
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatSocket)) To hoSocket
If (Not(IsComObjectCreated(hoSocket))) Begin
Send CreateComObject of hoSocket
End
// Connect to the SSH server and initialize an SSH tunneling session. Port 22 is conventional but
// not required.
Get ComSshOpenTunnel Of hoSocket "ssh.example.com" 22 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
// After the tunnel is open, authenticate before opening forwarded channels.
// The SSH password should come from a secure source rather than being hard-coded.
Move "mySshPassword" To sSshPassword
Get ComSshAuthenticatePw Of hoSocket "sshUser" sSshPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "SSH tunnel established and authenticated."
End_Procedure