Sample code for 30+ languages & platforms
JavaScript

Check SSH Connection (IsConnected)

Demonstrates how to check to see if the connection to the SSH server exists.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var ssh = new CkSsh();

// Connect to an SSH server:
success = ssh.Connect("192.168.1.209",22);
if (success !== true) {
    console.log(ssh.LastErrorText);
    return;
}

// Is the last known state "connected"?
var connected = ssh.IsConnected;
if (connected == true) {
    // Verify for sure by sending an ignore message.
    connected = ssh.SendIgnore();
}

console.log("connected = " + connected);

// Disconnect.
ssh.Disconnect();

// Am I still connected?
connected = ssh.IsConnected;
console.log("connected = " + connected);