Classic ASP
Classic ASP
Disconnect All SSH Tunnel Clients
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.DisconnectAllClients method, which disconnects all active tunnel clients while leaving the listener and SSH connection available. The only argument (waitForThreads) selects whether to wait for the client threads to exit.
Background: This is the complement of
StopAccepting: it clears out current clients but keeps accepting new ones, so the listener and SSH transport stay up. It is useful for forcibly resetting stuck or unwanted connections without tearing down the whole tunnel — for example, dropping all sessions before a maintenance action while leaving the tunnel ready to serve fresh connections immediately afterward.Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Demonstrates the SshTunnel.DisconnectAllClients method, which disconnects all active tunnel
' clients while leaving the listener and SSH connection available. The only argument
' (waitForThreads) selects whether to wait for the client threads to exit.
set tunnel = Server.CreateObject("Chilkat.SshTunnel")
tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432
sshPort = 22
success = tunnel.Connect("ssh.example.com",sshPort)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( tunnel.LastErrorText) & "</pre>"
Response.End
End If
' Normally you would not hard-code the password in source. You should instead obtain it
' from an interactive prompt, environment variable, or a secrets vault.
password = "mySshPassword"
success = tunnel.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( tunnel.LastErrorText) & "</pre>"
Response.End
End If
listenPort = 1080
success = tunnel.BeginAccepting(listenPort)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( tunnel.LastErrorText) & "</pre>"
Response.End
End If
' ... clients connect and transfer data ...
' Disconnect all current clients. The listener keeps running and will accept new clients.
waitForThreads = 1
success = tunnel.DisconnectAllClients(waitForThreads)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( tunnel.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "All current clients disconnected; still accepting new ones.") & "</pre>"
waitForThreadExit = 1
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( tunnel.LastErrorText) & "</pre>"
Response.End
End If
%>
</body>
</html>