Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Moving files between FTP servers

by Anonymous Monk
on Nov 08, 2000 at 22:09 UTC ( #40582=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need to move files from FTP server A to FTP server B, under the control of a program running on App server C.

Comment on Moving files between FTP servers
Re: Moving files between FTP servers
by arturo (Vicar) on Nov 08, 2000 at 22:12 UTC
    Look at Net::FTP. It should do everything you want it to.
Re: Moving files between FTP servers
by crutan (Novice) on Nov 09, 2000 at 22:37 UTC
    This is a script that does just that, it opens two connections and moves files between them.

    It does bring the file down to the local disk, though, so it may not be what you want.

    #!/usr/bin/perl -w use strict; use Net::FTP; use FileHandle; ### # A Script that will get files from one server object # stored in $ftp_a and put them onto a second server # object, $ftp_b. # # Objective is to do this using filehandles, and not # actually writing to disk. ### ### # File list. Generate however you want. ### my @file_list = ("some.file"); ### # Begin by opening the connections to the two servers # and logging in. ### my $ftp_a = Net::FTP->new("first.server.address", Debug => 0); my $ftp_b = Net::FTP->new("second.server.address", Debug=> 0); $ftp_a->login("first_server_username","first_server_password"); $ftp_b->login("second_server_username","second_server_password"); my $fh = FileHandle::new; foreach (@file_list) { $ftp_a->get($_,$fh); $ftp_b->put($fh,$_); unlink($fh); } $ftp_a->quit; $ftp_b->quit;
    PS:
    Does anyone know how to open a filehandle or filehandle-like object that Net::FTP can stream its data to? Like:
    get(remote_file,(put process on other server));
    I tried it with open $fh, "$ftp_b->put($_)"; but that didn't work.
      see the pasv_xfer command in Net::FTP
Re: Moving files between FTP servers
by mofo (Acolyte) on Jan 29, 2002 at 02:41 UTC
    Using filehandles in Net::FTP is simple.
    open(FH, $local_file) || die "Cannot open $local_file: $!"; $ftp=put(\*FH, $remote_file) || die "Upload of $local_file to $remote_ +file failed\n"; close(FH) || die "Cannot close $local_file (?!?): $!";

    Or you can do STDIN, which I find handy when gzipping a file across FTP in real time.
    $ftp=put(\*STDIN, $remote_file) || die "Upload from STDIN to $remote_f +ile failed\n";

    You can run it from command line like this:
    cat /var/log/messages |gzip -9fc | ./mystdinftp.pl

    -reid
Re: Moving files between FTP servers
by IlyaM (Parson) on Jan 29, 2002 at 04:47 UTC
    In addition to other replies I'd like to note that some FTP servers support direct file transfers. That is there is no need to download files from first server and then upload it on another. If FTP server supports it then files can be copied directly from one ftp server to another.

    See Net::FTP docs for description of pasv_xfer method.

Re: Moving files between FTP servers
by andybush (Initiate) on Jun 12, 2008 at 12:10 UTC
      Answer: You're an idiot!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://40582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-12-29 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls