tizen 2.3.1 release
[external/curl.git] / perl / contrib / recursiveftpget.pl.in
1 #!@PERL@
2 #
3 # Author:  Daniel Stenberg <Daniel.Stenberg@sth.frontec.se>
4 # Date:    August 25 1998
5 # Version: 0.1
6 #
7 # This is just meant as an example of why we wrote curl in the first place.
8 # Quick n' easy scripting use.
9 #
10
11 $dir = $ARGV[0];
12
13 $target = $ARGV[1];
14
15 $maxdepth = $ARGV[2];
16
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;
21 }
22
23 if(($maxdepth ne "") && ($maxdepth == 0)) {
24     # reached maximum depth, die
25     print "Reached maximum recursive depth level ($maxdepth), exiting...\n";
26     exit;
27 }
28
29 # get dir
30 @all = `curl -s $dir`;
31
32 if($all[0] ne "") {
33     print "Got the main $dir dir\n";
34 }
35
36 line:
37 for(@all) {
38     chop; # cut off newline
39     @linep= split(" ", $_);
40
41     $name = $linep[$#linep];
42
43     $firstletter=substr($linep[0], 0, 1);
44
45     if($firstletter eq "d") {
46         # this is a subdir, recurse
47         # if not . or .. of course
48
49         if(($name eq ".") || ($name eq "..")) {
50             next line;
51         }
52         print "Recursing for dir $dir$name in target $target/$name\n";
53
54         $nextdepth=$maxdepth-1;
55         print `$0 $dir$name/ $target/$name $nextdepth`;
56     }
57     elsif($firstletter eq "-") {
58         # this is a file, get it
59         # oh, make sure the target dir exists first
60
61         if(! -r $target ) {
62             mkdir($target,0777);
63         }
64         print "Getting file $dir$name in target $target/$name\n";
65         print `curl -s $dir$name >$target/$name`;
66     }
67 }