![]() |
Copying File Between Servers with PHP or Shell Commands
I have a DMZ set up with a web server (Ubuntu 11.04) and an application server (Ubuntu 11.10). I can call php files on one server from the other using LAMP. I have set things up so a user can upload files. The files are uploaded to a folder /var/www/dropbox on the web server. I would like to be able to add php code to copy the files from the web server to the application server. What would be the best way to do this in the PHP code? I could use a shell command and use something like
Code:
exec("Shell command");Any assistance would be greatly appreciated, Peter. |
I would not suggest doing this at all due to the security issues that stem from running arbitrary commands on demand. I would recommend looking at a cron job or something equivalent to push files to their destination asynchronously.
|
Quote:
Thanks, Peter. |
Code:
security issues in my copying using a bash file that anyone can execute but noone had read persmission for? The files would be automatically checked before and after the copy.In any case, a shell file requires read+execute permissions to run directly (eg ./my.sh). You could use Code:
bash my.sh |
Quote:
Quote:
Thanks, Peter. |
Depends on exactly what you want it to do.
A binary executable generated from C code only requires 'x' perm to run. A script file eg bash, perl etc either requires 'rx' if run directly, or at least 'r' if run by another exe eg '/bin/bash my.sh' or '/usr/bin/perl my.pl'. IE, the calling exe needs to be able to read the content in order to action it. To copy files between systems I recommend scp or sftp using ssh-auth-keys for automatic processes. I'm going to assume that you trust the file contents, obviously... HTH :) |
Hi,
I know I'm jumping into this thread a bit late, but I've something to add. Quote:
HTH, Evo2. |
Quote:
Code:
scp CMakeCache.txt 192.168.1.10:/home/peter/dropboxCode:
ssh: connect to host 192.168.1.10 port 22: Connection refusedCode:
sudo ufw statusCode:
To Action FromQuote:
Thanks, Peter. |
Quote:
Thanks, Peter. |
Quote:
The script which does the copying should probably use scp or rsync with ssh. Authentication should be done using rsa public/private keys. rcp is insecure. Evo2. |
Quote:
Thanks, Peter. |
| All times are GMT -5. The time now is 01:28 AM. |