首页 > IT职业 > IT图书 > php利用ssh操作远程服务器
首先,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/ ,如需转载,请注明出处,否则将追究法律责任。