Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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; } }

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

Comment on Mirror a local directory to an FTP server
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://573531]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-12-21 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (104 votes), past polls