您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 南充分类信息网,免费分类信息发布

php ssh2扩展操作类

2024/3/3 17:15:42发布20次查看
php 的ssh2扩展可以找度娘
host = $host; $this->user = $user; $this->password = $password; $this->connection = ssh2_connect ( $this->host, 22 ); if (! $this->connection) die ( 'connection to ' . $host . ':22 failed' ); $this->auth_methods = ssh2_auth_none ( $this->connection, $this->user ); } /** * 执行shell命令 * @return code 101:认证失败 * 102:通过password方式登录远程服务器失败 * 103:shell命令执行失败 * 200:操作成功 */ public function execshell($shell) { if (in_array ( 'password', $this->auth_methods )) { if (ssh2_auth_password ( $this->connection, $this->user, $this->password )) { $stream = ssh2_exec ( $this->connection, $shell ); // 执行php stream_set_blocking ( $stream, true ); // 获取执行pwd后的内容 if ($stream === false) { $this->data ['msg'] = 'shell命令执行失败'; } else { $this->data ['code'] = 200; $this->data ['msg'] = stream_get_contents ( $stream ); } } else { $this->data ['code'] = 102; $this->data ['msg'] = '通过password方式登录远程服务器失败'; } } else { $this->data ['code'] = 101; $this->data ['msg'] = '认证失败'; } return $this->data; }}$host='';$user='';$passwd='';$sshobj = new ssh($host, $user, $passwd);$rs = $sshobj->execshell('pwd');var_dump($rs);
南充分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录