Classic ASP
Classic ASP
Route Socket Connections through an SSH Object
See more Socket/SSL/TLS Examples
Demonstrates Socket.UseSsh, which configures a socket to route subsequent Connect calls through an already connected and authenticated Ssh object using SSH port forwarding.
Background. After UseSsh, the destination host and port passed to Connect are reached through the SSH tunnel rather than by a direct TCP connection. This is one of several SSH-tunneling approaches the Socket class supports.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set ssh = Server.CreateObject("Chilkat.Ssh")
' Connect and authenticate a standalone SSH object.
success = ssh.Connect("ssh.example.com",22)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( ssh.LastErrorText) & "</pre>"
Response.End
End If
' The SSH password should come from a secure source rather than being hard-coded.
sshPassword = "mySshPassword"
success = ssh.AuthenticatePw("sshUser",sshPassword)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( ssh.LastErrorText) & "</pre>"
Response.End
End If
set socket = Server.CreateObject("Chilkat.Socket")
' Route subsequent Connect calls through the already connected and authenticated SSH object. The
' destination is reached by SSH port forwarding rather than by a direct TCP connection.
success = socket.UseSsh(ssh)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
' Connect to the destination through the SSH tunnel.
bTls = 0
maxWaitMs = 5000
success = socket.Connect("db.internal",5432,bTls,maxWaitMs)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Connected to the destination through the SSH tunnel.") & "</pre>"
%>
</body>
</html>