/**
* 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) ***/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。