(PHP Extension) Check SSH Connection (IsConnected)
Demonstrates how to check to see if the connection to the SSH server exists.
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
$ssh = new CkSsh();
// Connect to an SSH server:
$success = $ssh->Connect('192.168.1.209',22);
if ($success != true) {
print $ssh->lastErrorText() . "\n";
exit;
}
// Is the last known state "connected"?
$connected = $ssh->get_IsConnected();
if ($connected == true) {
// Verify for sure by sending an ignore message.
$connected = $ssh->SendIgnore();
}
print 'connected = ' . $connected . "\n";
// Disconnect.
$ssh->Disconnect();
// Am I still connected?
$connected = $ssh->get_IsConnected();
print 'connected = ' . $connected . "\n";
?>
|