Visual FoxPro
Visual FoxPro
Open a Forwarded Channel through an SSH Tunnel
See more Socket/SSL/TLS Examples
Demonstrates Socket.SshNewChannel, which opens a port-forwarded channel through an authenticated SSH tunnel to a destination host and port, populating a Socket with the connected channel.
Background. Set the ssl argument to true to establish TLS to the destination inside the SSH tunnel. The returned channel socket is then used to send and receive with the destination.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSocket
LOCAL lcSshPassword
LOCAL lnBTls
LOCAL lnMaxWaitMs
LOCAL loChannel
lnSuccess = 0
loSocket = CreateObject('Chilkat.Socket')
* Connect to the SSH server and initialize an SSH tunneling session. Port 22 is conventional but
* not required.
lnSuccess = loSocket.SshOpenTunnel("ssh.example.com",22)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
CANCEL
ENDIF
* Authenticate the SSH session before opening forwarded channels.
* The SSH password should come from a secure source rather than being hard-coded.
lcSshPassword = "mySshPassword"
lnSuccess = loSocket.SshAuthenticatePw("sshUser",lcSshPassword)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
CANCEL
ENDIF
* Open a port-forwarded channel through the authenticated SSH tunnel to the destination host and
* port, populating a Socket with the connected channel. Set the 3rd argument to 1 to establish
* TLS to the destination inside the tunnel.
lnBTls = 0
lnMaxWaitMs = 20000
loChannel = CreateObject('Chilkat.Socket')
lnSuccess = loSocket.SshNewChannel("db.internal",5432,lnBTls,lnMaxWaitMs,loChannel)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
RELEASE loChannel
CANCEL
ENDIF
* Use the channel socket to send and receive with the destination through the tunnel.
? "Forwarded channel opened to the destination."
RELEASE loSocket
RELEASE loChannel