前端之家收集整理的这篇文章主要介绍了
php 通过ssh传输文件的ssh api类用法示例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
对
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) ***/
原文链接:https://www.f2er.com/php/528682.html