Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 04-16-2006, 04:07 AM   #1
LQ Newbie
Registered: Apr 2006
Location: US
Posts: 9

Rep: Reputation: 0
Question PERL: cgi script copy problem from server to another

Shortly: How to copy files (images) remotely between two servers by running cgi-script in web browser?

I'm trying to copy files (images) from server where script is working to another server while script running. In reality when people upload their picture to my website, it actually gets (or rather should get) copied to another website too (mirror copy).
Now, best way to do it so far I found out to be using $ftp->put. I can login to my server, read file and dir lists, create dirs, change to another dir, but can't upload. This is to remote server only. I can upload images to same server where script is running fine, but the problem is in FTP'ing part.
I made short script to create dir, then manually (by ws_ftp) chmoded it to 777 and tried to upload with no success. Running out of ideas. Only other way I can think of is pasv_xfer that I found from google, but never used it and can't make it work either. There must be better ways to do this. There's some code I've tried:

sub ftp_upload {
  $file = "http\:\/\/www\.sourceserver\.net\/pages\/folder\/upload\/dir\/img\/test\.jpg";
  $ftp->put ($file) or print "problem1<br>";
} # End of ftp_upload subroutine.
I'm also using print "Content-type: text/html\n\n"; to make it work thru browser.

Thanks in advance!

Old 04-16-2006, 09:42 PM   #2
Senior Member
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
have you checked to make sure that your FTP server's perl directory has the ftp module installed? that could be the root of your problems. I have my own ftp server, and I needed to use perl's CGI module, and it wouldn't work on a cgi script because I didn't have the CGI module installed in my server's perl dir. so, I installed the CGI module, and everything works beautifully now.
Old 04-16-2006, 10:14 PM   #3
LQ Newbie
Registered: Apr 2006
Location: US
Posts: 9

Original Poster
Rep: Reputation: 0
I'm using this line of code at the beginning of the script: use Net::FTP;. So as far as I know,I have what you're suggesting for. Also I can use $ftp->login(); and other commands with no problem to login, to read dir, to create dir, and to change dir. Only when trying to upload file using $ftp->put ($file);, it won't work.

How do you set variable which indicates the file path for the source file? Do you use it like I'm using on original posting: $file = "http\:\/\/www\.sourceserver\.net\/pages\/folder\/upload\/dir\/img\/test\.jpg";
or should it be something different? Or should it be more like: $file = "/sourceserver-www/pages/folder/upload/dir/img/test.jpg"; (just like reading file normally in the script when _not_ using ftp)? It must have something to do with the part where script can't either find the source file (wrong or wrongly written path) or then it can't read the file for reason or the other.

Sorry if this is explained too complicated. Hope someone could make sense out of this!



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 can`t make file.Why? ZairSadiqov Linux - Software 1 11-22-2006 08:22 AM
exec a C prg in a CGI Perl script jagman Linux - Networking 2 05-31-2005 11:40 AM
call perl cgi script from php j-ray Programming 2 01-14-2005 09:23 AM
CGI/Perl script problems. Randvegeta Linux - Software 8 12-30-2004 01:24 AM
Need Help With My Perl/cgi Authentication Script dutch357 Programming 0 04-11-2003 10:54 AM

All times are GMT -5. The time now is 10:36 AM.

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