recursiveftpget.pl.in 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $dir = $ARGV[0];
  11. $target = $ARGV[1];
  12. $maxdepth = $ARGV[2];
  13. if($dir eq "" || $target eq "") {
  14. print "Usage: <URL> <dir> [max depth level] \n";
  15. print " End the URL with a slash if a directory is specified, please\n";
  16. exit;
  17. }
  18. if(($maxdepth ne "") && ($maxdepth == 0)) {
  19. # reached maximum depth, die
  20. print "Reached maximum recursive depth level ($maxdepth), exiting...\n";
  21. exit;
  22. }
  23. # get dir
  24. @all = `curl -s $dir`;
  25. if($all[0] ne "") {
  26. print "Got the main $dir dir\n";
  27. }
  28. line:
  29. for(@all) {
  30. chop; # cut off newline
  31. @linep= split(" ", $_);
  32. $name = $linep[$#linep];
  33. $firstletter=substr($linep[0], 0, 1);
  34. if($firstletter eq "d") {
  35. # this is a subdir, recurse
  36. # if not . or .. of course
  37. if(($name eq ".") || ($name eq "..")) {
  38. next line;
  39. }
  40. print "Recursing for dir $dir$name in target $target/$name\n";
  41. $nextdepth=$maxdepth-1;
  42. print `$0 $dir$name/ $target/$name $nextdepth`;
  43. }
  44. elsif($firstletter eq "-") {
  45. # this is a file, get it
  46. # oh, make sure the target dir exists first
  47. if(! -r $target ) {
  48. mkdir($target,0777);
  49. }
  50. print "Getting file $dir$name in target $target/$name\n";
  51. print `curl -s $dir$name >$target/$name`;
  52. }
  53. }