欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

php实现的ssh api类,php实现sshapi,class SshApi

来源: javaer 分享于  点击 41234 次 点评:168

php实现的ssh api类,php实现sshapi,class SshApi


class SshApi extends BaseObject{   public $session = null;   public $authenticated = false;   public function __construct(){   }   public function connect($host){      $this->session = ssh2_connect($host);      return $this->session;   }   public function pubkeyFile($sshUser, $sshPub, $sshPriv, $sshPass){      if ( ! $this->session ) return false;      if ( empty($sshPass) ){         $b = ssh2_auth_pubkey_file( $this->session, $sshUser, $sshPub, $sshPriv);      }      else         $b = ssh2_auth_pubkey_file( $this->session, $sshUser, $sshPub, $sshPriv, $sshPass);      if ( $b ) $this->authenticated = true;      return $b;   }   public function send($localfile, $remotefile, $perms=0660){      $this->debug(__METHOD__);      if ( ! $this->session ) return false;      $this->debug('Sending '. $localfile . ' to ' . $remotefile);      $b = ssh2_scp_send($this->session, $localfile, $remotefile, $perms);            return $b;   }   public function recv($remotefile , $localfile){      if ( ! $this->session ) return false;      $b = ssh2_scp_recv($this->session , $remotefile , $localfile );      return $b;   }   public function exec($command){      if ( ! $this->session ) return false;         $stream = ssh2_exec($this->session, $command);      return $stream;   }}
相关栏目:

用户点评