ITPub博客

首页 > IT职业 > IT图书 > php利用ssh操作远程服务器

php利用ssh操作远程服务器

IT图书 作者:disable 时间:2021-09-09 09:22:19 0 删除 编辑

首先,php需要支持ssh2的扩展。

1登陆

$connection=ssh2_connect($ip,$port);

ssh2_auth_password($connection,$username,$password);

2执行命令

$get_devices = "adb devices";

$stream = ssh2_exec($connection , $get_devices);

3获取命令执行结果

stream_set_blocking($stream, true);

$output = stream_get_contents($stream);

fclose($stream);

此时,获取string类型的output。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/200/viewspace-2809763/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2018-09-12

  • 博文量
    86
  • 访问量
    16279