[英]PHP ssh2_exec returning stream, but remote command not being run
我正在嘗試使用ssh2模塊在遠程服務器上運行命令。 日志顯示認證成功,並且ssh2_exec返回流(記錄的成功行為)。
服務器端,以手動方式(通過膩子)以SSH身份登錄到服務器,這使我能夠成功運行命令。
但是,當運行我的代碼時,我的日志顯示該命令甚至從未被調用過。
這是控制會話的代碼:
function connect() {
$hnd = \ssh2_connect(Config\PORTAL_SERVER);
if (!$hnd) return false;
if (!\ssh2_auth_password($hnd, Config\PORTAL_USER, Config\PORTAL_PASSWD))
return false;
return $hnd;
}
function run($api, $function, $args, $hnd) {
$args = implode(' ', $args);
$stream = \ssh2_exec($hnd, "api $api $function $args");
\stream_set_blocking($stream, true);
$response = \stream_get_contents($stream);
fclose($stream);
return \json_decode($response);
}
和調用它的代碼:
$hnd = Portal\connect();
$result = Portal\run(
'users',
'all',
array(),
$hnd
);
json_decode接收到一個空字符串,因為流從不返回任何內容。 我只能假定我以某種方式對流進行了錯誤處理,但這不能解釋我的命令未運行。
我是個白痴。
在會話開始時,沒有為用戶正確設置路徑。我切換到絕對路徑,一切都變得完美。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.