LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PERL: cgi script copy problem from server to another (https://www.linuxquestions.org/questions/programming-9/perl-cgi-script-copy-problem-from-server-to-another-435595/)

<db> 04-16-2006 04:07 AM

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:

Code:

sub ftp_upload {
  $ftp->binary();
  $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!

<db>

indienick 04-16-2006 09:42 PM

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.

<db> 04-16-2006 10:14 PM

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!

<db>


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