【发布时间】:2019-11-19 14:13:44
【问题描述】:
我正在尝试 ssh 到远程服务器以检查特定文件是否存在。
我可以在命令行中进行 ssh,但每当我尝试使用我的脚本时,它不会返回任何内容/我必须输入“exit”并按 Enter 键才能返回命令行。
步骤:
- ssh root@website.com
- cd ..
- ls ATMEXTRACT
我将所有这些命令放入输出中,因此它们看起来像这样:
$output = shell_exec("ssh root@website.com");
$ouput1 = shell_exec("cd ..");
$ouput2 = shell_exec("ls *ATMEXTRACT*");
echo($output2);
我很困惑为什么这直接在命令行中工作但在脚本中失败。非常感谢任何帮助
【问题讨论】:
-
这个问题最好用很长的解释来回答 shell_exec 真正的工作原理,并在这里解释你的误解。我不知道从哪里开始,但与此同时,对于您正在做的事情,请考虑 PHP 的 SSH2 extension
-
还要考虑 PHP 的 FTP 函数,和this other question
标签: php linux shell ssh remote-server