Tinker and exec run with your privileges, access to your stored keys etc.. this is not true when you run from browser or cron.
Have you tried ssh2_scp_recv ? (http://php.net/manual/en/function.ssh2-scp-recv.php)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Aloha,
Could someone please help me with some things that I could look at in order to download files from a remote server?
I am attempting to use scp to download the files from the remote server. The code in my controller is just this:
public function getTest()
{
exec("scp [email protected]:/path/to/files/* /local/path/");
}
If I run the exec command with php -r, it works. Similarly, if I open tinker, and run (new App\Http\Controllers\TestController)->getTest(), it works.
I have found that it does not work when I open the page in a browser. It also does not work if I run it as a scheduled job. It does work if I manually run the exec command from artisan, though.
Right now, I'm doing this on a homestead box. 'vagrant' is both the local user and the web user, so I believe that access should be the same? Is there any reason it wouldn't be?
I have also tried using the -i option to explicitly set the key file. I've also tried setting up a ~/.ssh/config file.
I've spent all day on this, and am now thoroughly confused. Any ideas on things to look at?
Thank you,
--joel
Tinker and exec run with your privileges, access to your stored keys etc.. this is not true when you run from browser or cron.
Have you tried ssh2_scp_recv ? (http://php.net/manual/en/function.ssh2-scp-recv.php)
Please or to participate in this conversation.