|
对php实现的ssh api类,主要用来通过ssh传输文件感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编两巴掌来看看吧!
/**
* php实现的ssh api类,主要用来通过ssh传输文件
*
* @param
* @author 网: jb51.cc
**/
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,$sshPriv);
}
else
$b = ssh2_auth_pubkey_file( $this->session,$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,$perms);
return $b;
}
public function recv($remotefile,$localfile){
if ( ! $this->session ) return false;
$b = ssh2_scp_recv($this->session,$localfile );
return $b;
}
public function exec($command){
if ( ! $this->session ) return false;
$stream = ssh2_exec($this->session,$command);
return $stream;
}
}
/*** 来自脚本之家 jb51.cc(jb51.cc) ***/ (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|