LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2006, 06:32 PM   #1
<db>
LQ Newbie
 
Registered: Apr 2006
Location: US
Posts: 9

Rep: Reputation: 0
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>
 
Old 04-18-2006, 02:29 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
Old 04-18-2006, 05:33 AM   #3
<db>
LQ Newbie
 
Registered: Apr 2006
Location: US
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks chrism01, I will give it a try!

<db>
 
Old 04-26-2006, 06:22 PM   #4
<db>
LQ Newbie
 
Registered: Apr 2006
Location: US
Posts: 9

Original Poster
Rep: Reputation: 0
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>
 
Old 04-26-2006, 07:08 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PERL: cgi script copy problem from server to another <db> Programming 2 04-16-2006 09:14 PM
Automatically copy images off digital camera taboom Linux - Software 7 08-31-2005 03:07 PM
Copy images from terminal ThePenguin Linux - Newbie 2 09-05-2004 12:54 PM
perl -MCPAN -e shell, resetting or changing mirror urls msteudel Linux - Software 3 04-23-2004 09:50 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration