php实现的ssh api类,主要用来通过ssh传输文件
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;
}
}
开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明php实现的ssh api类!