Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Mirror a local directory to an FTP server

by davis (Vicar)
on Sep 18, 2006 at 11:54 UTC ( #573531=CUFP: print w/replies, xml ) Need Help??

This is disgusting, but it's a just a quick-n-dirty hack to upload a directory structure to a remote FTP server where the FTP server would only allow one "put" command per login session. Yes, really. Obviously there was no ssh access otherwise I would have used rsync/scp -r. Oh well.
#!/usr/bin/perl use warnings; use strict; use Net::FTP; use File::Basename; my $startdir = "somewhere"; my $ftphost = "somehost"; my $ftpuser = "someuser"; my $ftppass = "somepass"; upload_dir($startdir); sub upload_dir { my $dir = shift; foreach my $entry (<$dir/*>) { upload_dir($entry) if(-d $entry); my $ftp = Net::FTP->new($ftphost) or die "Can't connect to $ftphost: $@"; $ftp->login($ftpuser, $ftppass) or die "Can't login ", $ftp->message; my $dirname = dirname $entry; $ftp->mkdir($dirname, 1); $ftp->cwd($dirname); $ftp->put($entry); $ftp->quit; } }

Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://573531]
Approved by Limbic~Region
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-06-21 03:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.