Copying File Between Servers with PHP or Shell Commands
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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");
but do not know what shell command would be best to use.
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.
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.
It seems that Cron is for scheduling tasks. I would want the clients files to be copied pretty well immediately so that they can start processing them with the software I have written. Would there be 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.
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.
If you've got method for auto-checking a shell file for exploits that actually works, I'd very surprised .. I believe the general case is unsolvable.
In any case, a shell file requires read+execute permissions to run directly (eg ./my.sh). You could use
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.
If you've got method for auto-checking a shell file for exploits that actually works, I'd very surprised .. I believe the general case is unsolvable.
Currently the files that are uploaded must be one of two formats. If neither of those formats, the files is rejected.
Quote:
Originally Posted by chrism01
In any case, a shell file requires read+execute permissions to run directly (eg ./my.sh). You could use
Code:
bash my.sh
which only requires that the sh file be readable.
If I did not want to use a file with read permissions, could I write an executable in C++ and make a system call? If so, what would be the best system call to use?
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...
I know I'm jumping into this thread a bit late, but I've something to add.
Quote:
Originally Posted by OtagoHarbour
It seems that Cron is for scheduling tasks. I would want the clients files to be copied pretty well immediately so that they can start processing them with the software I have written.
It looks like what you want is actually "incron", which is similar to cron but it performs actions based on filesystem events instead of time(s).
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.
Thank you for the reply. would that be better than rcp?
No, you would use it to automatically run a script to copy the files that appear on disk.
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.
No, you would use it to automatically run a script to copy the files that appear on disk.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.