php实现的ssh api类,php实现sshapi,class SshApi
分享于 点击 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; }}
用户点评