开发者

copy using PHP exec command and scp

I want to copy a zip file from remote to my local system using SCP. I have a php file where i use php function exec(); if i run upload.php like http://www.abc.com/upload.php. The zip file should copy to my local linux folder my path is /var/www/html/mydire开发者_运维百科ctory/ How can i do this ?


You can use PHP's PECL ssh2 extension that provides ssh2_scp_send.


In order to automate any ssh connection like scp you have to set up a pair of auth keys.

This will allow your remote computer to connect to your local computer with out a password prompt. A simple google search will show you how to set this up. The resource I used is http://linuxproblem.org/art_9.html.

The auth key allow the computers to recognize each other and handshake with out a user prompt but remember doing this does provide free ssh access from your remote location to your home computer without a password, so handle permissions carefully.

A better way than an scp if you don't need encryption is to set up a wget on your local computer to grab off your remote computer's web dir.


To me, it seems like you are asking how to download a zip file from your remote web server. In that case, you could simply give the browser the direct path to the zip and let it download it. You can't push a file from the server to the local machine with SCP. Use HTTPS if you're concerned about security. If the zip file is outside of the web directory, you can use PHP to read the file (assuming apache has access to it) and then output it to the browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜