2014-01-09 118 views
0

我想使用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成功接收过

有谁知道这可能是为什么?

+1

您是否已将密钥添加到网络服务器帐户的authorized_keys中?仅仅因为它可以在你的权限下运行的shell运行,这对于在web服务器的ID下运行的shell毫无意义。 –

+0

ooooh yeahhhhh ....我忘记了那个 – John

+0

它的工作。谢谢Marc! – John

回答

0

马克乙回答我的问题与评论...在这里发帖

你添加的关键web服务器的帐户的authorized_keys的?仅仅因为它可以在你的权限下运行的shell运行,这对于在web服务器的ID下运行的shell毫无意义。 - 马克·乙1月9日在19:47

OOOOH yeahhhhh ....我忘了这一点约翰 - 1月9日在19:57

烨它的工作。谢谢Marc! - John Jan 9 at 20:42