Sample code for 30+ languages & platforms
VBScript

Disconnect from an SSH Server

See more SSH Examples

Demonstrates the Chilkat Ssh.Disconnect method, which closes the current SSH transport. It takes no arguments, is harmless to call when nothing is connected, and may be called repeatedly.

Background: Disconnecting tears down the transport and every channel opened on it; afterward IsConnected is false and NumOpenChannels is 0. Bytes already buffered for a former channel can still be read after disconnect, which is useful when you want to drain a command's final output before releasing the session.

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

'  Demonstrates the Ssh.Disconnect method, which closes the current SSH transport.  It takes no
'  arguments, is safe to call when no connection exists, and may be called repeatedly.

set ssh = CreateObject("Chilkat.Ssh")

'  Connect to the SSH server.  Port 22 is the usual SSH port.
sshPort = 22
success = ssh.Connect("ssh.example.com",sshPort)
If (success = 0) Then
    outFile.WriteLine(ssh.LastErrorText)
    WScript.Quit
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 = ssh.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
    outFile.WriteLine(ssh.LastErrorText)
    WScript.Quit
End If

'  ... use the SSH connection ...

'  Close the SSH connection.
ssh.Disconnect 

outFile.Close