shivamem has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I need a perl script or module which could ftp a file from A server to B server and from B to C server and the script should be running on A server. and there is no connection between A to C and for each server(A,B,C) user and password authentication is required. please help on it. i had writen a script on below plese look into it and help me on it.

on server A some.hostA.com the below script have been writen. and trying to execute on the A server.

#!/usr/bin/perl use Net::FTP; $ftp = Net::FTP->new("some.hostB.com", Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login("xxx",'xxx') or die "Cannot login ", $ftp->message; #$ftp->cwd("/pub") # or die "Cannot change working directory ", $ftp->message; $ftp->put("cron/eid_inv_ftp.pl"); $newftp = Net::FTP->new("some.hostC.com", Debug => 0) or die "Cannot connect to some.host1.name: $@"; $newftp->login("xxxx",'xxx') or die "Cannot login ", $newftp->message; print $newftp->pwd(); $newftp->put($ftp->get("/export/home/xx/debugtrans.pl")) or die "put failed ", $newftp->message; $newftp->quit; $ftp->quit;

Replies are listed 'Best First'.
Re: ftping a file from a remote server to another remote server
by marto (Cardinal) on Jul 19, 2011 at 09:01 UTC

    Welcome to the Monastery.

    Firstly you've posted in the wrong section of the forum (see Where should I post X?). You should look at using the Net::FTP module. You may want to read up on FTP security if you're not already familiar with the issues involved.

      hi marto,

      Thanks for your reply,

      here is my code.

      I need a perl script or module which could ftp a file from A server to B server and from B to C server and the script should be running on A server. and there is no connection between A to C and for each server(A,B,C) user and password authentication is required. please help on it. i had writen a script on below plese look into it and help me on it. on server A some.hostA.com the below script have been writen. and trying to execute on the A server.

      #!/usr/bin/perl use Net::FTP; $ftp = Net::FTP->new("some.hostB.com", D +ebug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login +("xxx",'xxx') or die "Cannot login ", $ftp->message; #$ftp->cwd("/pub +") # or die "Cannot change working directory ", $ftp->message; $ftp-> +put("cron/eid_inv_ftp.pl"); $newftp = Net::FTP->new("some.hostC.com", + Debug => 0) or die "Cannot connect to some.host1.name: $@"; $newftp- +>login("xxxx",'xxx') or die "Cannot login ", $newftp->message; print +$newftp->pwd(); $newftp->put($ftp->get("/export/home/xx/debugtrans.pl +")) or die "put failed ", $newftp->message; $newftp->quit; $ftp->quit +;
        You should put <code> </code> tags around your code so that formatting (like line breaks) is preserved.

        Your approach is faulty:
        $newftp->put($ftp->get("/export/home/xx/debugtrans.pl"))
        You can't do a "put" of a "get". Two steps are required. You need to connect to B, download (get) the file onto machine A (your machine). Then connect to C and upload (put) the file.

        Start with one step at a time. First get the download of the file from machine B to machine A working. Then try connecting and uploading to C.

        Read the documentation carefully about "where" the file will go..