Sample code for 30+ languages & platforms
VBScript

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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

set socket = CreateObject("Chilkat.Socket")

'  Connect to the SSH server and initialize an SSH tunneling session.  Port 22 is conventional but
'  not required.
success = socket.SshOpenTunnel("ssh.example.com",22)
If (success = 0) Then
    outFile.WriteLine(socket.LastErrorText)
    WScript.Quit
End If

'  Authenticate the SSH session before opening forwarded channels.
'  The SSH password should come from a secure source rather than being hard-coded.
sshPassword = "mySshPassword"
success = socket.SshAuthenticatePw("sshUser",sshPassword)
If (success = 0) Then
    outFile.WriteLine(socket.LastErrorText)
    WScript.Quit
End If

'  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.
bTls = 0
maxWaitMs = 20000
set channel = CreateObject("Chilkat.Socket")
success = socket.SshNewChannel("db.internal",5432,bTls,maxWaitMs,channel)
If (success = 0) Then
    outFile.WriteLine(socket.LastErrorText)
    WScript.Quit
End If

'  Use the channel socket to send and receive with the destination through the tunnel.
outFile.WriteLine("Forwarded channel opened to the destination.")

outFile.Close