LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PERL: how to mirror copy images to another server? (https://www.linuxquestions.org/questions/programming-9/perl-how-to-mirror-copy-images-to-another-server-436175/)

<db> 04-17-2006 06:32 PM

PERL: how to mirror copy images to another server?
 
What is the right way (or any way) to automatically make a mirror copy of an image file to another server when running perl script? I have a script where user submits formdata (text) and same time the script should make a mirror copy of a certain file to another server. This is needed, because I'd like to run script only on server1 but have all pictures uploaded/stored to server2. Server2 would not have any scripts running in it if possible. Currently I get pictures uploaded to server1 where they should be copied/moved to server2.
My hosting company has perl 5.8.0 installed (and php 4.3.10 if it matters).

This is the idea:

http://www.server1.com/dirA/image1.jpg
-to-
http://www.server2.com/dirB/image1.jpg


I don't post any code with this question to not narrow your mindflow. I've days/nights worth of test code, which fails no matter what I do. I'd like to know what you would do in this case. Thanks in advance!

<db>

chrism01 04-18-2006 02:29 AM

I'd be tempted to use an existing tool like rsync, which you can call via eg system() or also call as a perl module: http://search.cpan.org/~leakin/File-Rsync-0.42/Rsync.pm

<db> 04-18-2006 05:33 AM

Thanks chrism01, I will give it a try!

<db>

<db> 04-26-2006 06:22 PM

ANSWER:

Got it working with help of my hosting tech support and perlmonks.com

use Net::FTP;
$ftp = Net::FTP->new($server_name, Debug => 1);
$ftp->login($ftp_username,$ftp_password);
$ftp->cwd($ftp_destination_dir);
$ftp->binary();
$ftp->put($ftp_source_image, $ftp_destination_image);
$ftp->quit;

You may want to log errors using $ftp->message in case you run on some troubles. And maybe good to use it in anycase to solve problems later if they happen. The issue with this in my case was I wasn't using proper dir info. If it does not work, make sure you're using proper dirs including root dir and so on. Pretty useful, easy to use and shortly written piece of script. Needs only a Net::FTP.

<db>

paulsm4 04-26-2006 07:08 PM

NFS-mounting one of Server2's drives on Server1, then writing to it directly from your Server1 CGI script, might also be a solution...


All times are GMT -5. The time now is 09:44 AM.