Initial revision
[libcurl.git] / perl / recursiveftpget.pl
blob02299b00d1eb478ecb202e8bc1ec114ec2c814a0
1 #!/usr/local/bin/perl
3 # Author: Daniel Stenberg <Daniel.Stenberg@sth.frontec.se>
4 # Date: August 25 1998
5 # Version: 0.1
7 # This is just meant as an example of why we wrote curl in the first place.
8 # Quick n' easy scripting use.
11 $dir = $ARGV[0];
13 $target = $ARGV[1];
15 $maxdepth = $ARGV[2];
17 if($dir eq "" || $target eq "") {
18 print "Usage: <URL> <dir> [max depth level] \n";
19 print " End the URL with a slash if a directory is specified, please\n";
20 exit;
23 if(($maxdepth ne "") && ($maxdepth == 0)) {
24 # reached maximum depth, die
25 print "Reached maximum recursive depth level ($maxdepth), exiting...\n";
26 exit;
29 # get dir
30 @all = `curl -s $dir`;
32 if($all[0] ne "") {
33 print "Got the main $dir dir\n";
36 line:
37 for(@all) {
38 chop; # cut off newline
39 @linep= split(" ", $_);
41 $name = $linep[$#linep];
43 $firstletter=substr($linep[0], 0, 1);
45 if($firstletter eq "d") {
46 # this is a subdir, recurse
47 # if not . or .. of course
49 if(($name eq ".") || ($name eq "..")) {
50 next line;
52 print "Recursing for dir $dir$name in target $target/$name\n";
54 $nextdepth=$maxdepth-1;
55 print `$0 $dir$name/ $target/$name $nextdepth`;
57 elsif($firstletter eq "-") {
58 # this is a file, get it
59 # oh, make sure the target dir exists first
61 if(! -r $target ) {
62 mkdir($target,0777);
64 print "Getting file $dir$name in target $target/$name\n";
65 print `curl -s $dir$name >$target/$name`;