Login   Register  
PHP Classes
elePHPant
Icontem

File: ssh_in_php_ex.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Filip  >  SSH in PHP  >  ssh_in_php_ex.php  >  Download  
File: ssh_in_php_ex.php
Role: Example script
Content type: text/plain
Description: Example of ssh in php class usage
Class: SSH in PHP
SSH client implementation in pure PHP
Author: By
Last change: forgotten to backslash $ in eregs
Date: 2005-07-31 06:37
Size: 856 bytes
 

Contents

Class file image Download
<?php

require_once ('ssh_in_php.php');

$host "127.0.0.1";
$port 22;
$user "user";
$password "pass";

try {
    
$ssh = new SSH_in_PHP($host,$port);
    
$ssh->connect($user,$password);

    
$cycle true;
    while (
$cycle) {
        
$data $ssh->read();
        echo 
$data;
        if (
ereg('\$',$data)) {
            
$cycle false;
        }
    }
    
$ssh->write("uname -a\n");
    
$cycle true;
    while (
$cycle) {
        
$data $ssh->read();
        echo 
$data;
        if (
ereg('\$',$data)) {
            
$cycle false;
        }
    }
    
    
$ssh->write("ls -al\n");
    
$cycle true;
    while (
$cycle) {
        
$data $ssh->read();
        echo 
$data;
        if (
ereg('\$',$data)) {
            
$cycle false;
        }
    }

    
$ssh->disconnect();

} catch (
SSHException $e) {
    echo 
"An Exception Occured: {$e->getMessage()} ({$e->getCode()})\n";
    echo 
"Trace: \n";
    echo 
print_r($e->getTrace());
    echo 
"\n";
}

?>