使用ssh2 执行远程机器命令 获取执行结果

 

<?php
$connect=ssh2_connect("www.superserver.com",22);
ssh2_auth_password($connect,'HonestQiao','123456');
$stream=ssh2_exec($connect, "cd /usr;ls;");
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
fclose($stream);
echo $output ;
?>

结果如下:
---------- PHP5 代码调试 ----------
bin
compat
db
games
home
include
lib
libdata
libexec
local
obj
ports
sbin
share
src

输出完成 (耗时 3 秒) - 正常终止
原文地址:https://www.cnblogs.com/mouseleo/p/14753943.html