简体   繁体   中英

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/mydirectory/ How can i do this ?

您可以使用提供ssh2_scp_send的 PHP的PECL ssh2扩展

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM