PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Igor Dyshlenko   PHP Shell Connector   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Shell Connector
Connect and run remote shell commands using ssh
Author: By
Last change:
Date: 6 years ago
Size: 1,851 bytes
 

Contents

Class file image Download

shell

v 1.02b

PHP connect to remote host over ssh

Connect to a remote host through the adapter class. Write / read data to the stream, execute commands on the remote host, obtain the result of the execution of commands. The bundled adapter class for connecting to ssh2. It is possible to develop an adapter class for telnet without modifying the existing code.

Example of using:

// Load classes files.
require_once 'din70/Tools/ShellAccess/ShellConnectorInterface.php';
require_once 'din70/Tools/ShellAccess/LogWrapper.php';
require_once 'din70/Tools/ShellAccess/Ssh2Connector.php';
require_once 'din70/Tools/ShellAccess/Shell.php';

// Logger initialization
require_once 'Log.php';
$logger = Log::singleton('console');
$logger->setMask(PEAR_LOG_ALL);

const HOST = 'localhost';
const COMMAND = 'df -lh';
const
    LOGIN = 'user',
    PASSWORD = 'password';

$shell = new Shell(new Ssh2Connector(HOST, 22, $logger), null, null, $logger);

echo "\n\n<b>Login as ", LOGIN, ', password ', PASSWORD, "</b>\n";
$shell->login(LOGIN, PASSWORD);

echo "\nisConnected() = ";
var_dump($shell->isConnested());

echo "\nisLoggedIn() = ";
var_dump($shell->isLoggedIn());

echo "\nisOnline() = ";
var_dump($shell->isOnLine());

$shell->eol("\r");                // Set end-of-line symbol
echo "\ngoAhead().\n";
$shell->goAhead();                // Get all chars before command prompt to internal buffer.
echo "\ngetResult() = ";
var_dump($shell->getResult());    // Get data from internal buffer.

// Execute command
echo "\n\n<b>Execute command \"", COMMAND, "\"</b>\n";
var_dump($result = $shell->exec(COMMAND));

echo "\n\n<b>Logout ", LOGIN, "</b>\n";
$shell->logout();

echo "\nisConnected() = ";
var_dump($shell->isConnested());

echo "\nisLoggedIn() = ";
var_dump($shell->isLoggedIn());

echo "\nisOnline() = ";
var_dump($shell->isOnLine());