I want to use PHP to run a shell script that sends a file from server 1 to server 2. I have the server 1 public key written to the server 2 authorized_keys and it works perfectly.
For some reason the following script doesn't actually send the file from server 1 to server 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 someuser@server2.net:
So when I execute from scp.sh
from terminal, everything works fine - the file actually gets sent and received.
But when I go to http://server1.com/sendfile.php
and press the button, the php file actually executes the shell file (i confirmed this by putting echo statements before and after scp command), but the file is never successfully received by server2.com
Does anyone know why this might be?