LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Copying File Between Servers with PHP or Shell Commands (http://www.linuxquestions.org/questions/linux-software-2/copying-file-between-servers-with-php-or-shell-commands-4175414214/)

OtagoHarbour 06-30-2012 07:48 PM

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.

acid_kewpie 07-02-2012 09:04 AM

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.

OtagoHarbour 07-04-2012 12:20 PM

Quote:

Originally Posted by acid_kewpie (Post 4717104)
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.

Thanks,
Peter.

chrism01 07-04-2012 08:19 PM

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.
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
Code:

bash my.sh
which only requires that the sh file be readable.

OtagoHarbour 07-06-2012 07:00 AM

Quote:

Originally Posted by chrism01 (Post 4719461)
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.
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 (Post 4719461)
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?

Thanks,
Peter.

chrism01 07-09-2012 09:55 PM

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
:)

evo2 07-09-2012 10:41 PM

Hi,

I know I'm jumping into this thread a bit late, but I've something to add.
Quote:

Originally Posted by OtagoHarbour (Post 4719193)
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).

HTH,

Evo2.

OtagoHarbour 07-12-2012 10:43 PM

Quote:

Originally Posted by chrism01 (Post 4723474)
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 tried

Code:

scp CMakeCache.txt 192.168.1.10:/home/peter/dropbox
and got

Code:

ssh: connect to host 192.168.1.10 port 22: Connection refused
lost connection

When I enter


Code:

sudo ufw status
on 192.168.1.10, I get, among other things,
Code:

To            Action        From
Anywhere      ALLOW          192.168.1.5

I am trying to copy from 192.168.1.5

Quote:

I'm going to assume that you trust the file contents, obviously...

HTH
:)
LOL. Not entirely although they should be from registered users. I plan to have several layers of checks for what is uploaded.

Thanks,
Peter.

OtagoHarbour 07-12-2012 10:46 PM

Quote:

Originally Posted by evo2 (Post 4723500)
Hi,

I know I'm jumping into this thread a bit late, but I've something to add.

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).

HTH,

Evo2.

Thank you for the reply. would that be better than rcp?

Thanks,
Peter.

evo2 07-12-2012 11:27 PM

Quote:

Originally Posted by OtagoHarbour (Post 4726588)
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.

Evo2.

OtagoHarbour 07-14-2012 04:52 PM

Quote:

Originally Posted by evo2 (Post 4726610)
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.

Evo2.

Sorry. I meant to say scp, not rcp.

Thanks,
Peter.


All times are GMT -5. The time now is 08:11 AM.