我想使用PHP来运行一个shell脚本,将文件从服务器1发送到服务器2.我有服务器1的公钥写入服务器2 authorized_keys,它的工作原理完美。PHP运行一个shell脚本到scp
出于某种原因,下面的脚本实际上并没有从服务器1发送文件到服务器2:
// This is a webpage at http://server1.com/sendfile.php
<?php
if($_POST['a'])
{
echo '<pre>';
echo passthru('./scp.sh');
echo '</pre>';
}
?>
<form method="post">
<button name="a" value="Af">Send File</button>
</form>
//This is the contents of scp.sh
scp ../dbexport/db.txt [email protected]:
所以,当我从scp.sh
从终端执行,一切工作正常 - 该文件实际上被发送和接收。
但是当我去http://server1.com/sendfile.php
并按下按钮时,php文件实际上执行shell文件(我通过在scp命令之前和之后放置echo语句来确认这一点),但该文件从未被server2.com成功接收过
有谁知道这可能是为什么?
您是否已将密钥添加到网络服务器帐户的authorized_keys中?仅仅因为它可以在你的权限下运行的shell运行,这对于在web服务器的ID下运行的shell毫无意义。 –
ooooh yeahhhhh ....我忘记了那个 – John
它的工作。谢谢Marc! – John