home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / bin / lwp-mirror < prev    next >
Encoding:
Text File  |  1997-08-10  |  2.4 KB  |  105 lines

  1. #perl -w
  2.     eval 'exec perl -S $0 "$@"'
  3.     if 0;
  4.  
  5. # $Id: lwp-mirror.PL,v 1.16 1996/05/19 11:22:34 aas Exp $
  6. #
  7. # Simple mirror utility using LWP
  8.  
  9. =head1 NAME
  10.  
  11. lwp-mirror - Simple mirror utility for WWW
  12.  
  13. =head1 SYNOPSIS
  14.  
  15.  lwp-mirror [-v] [-t timeout] <url> <local file>
  16.  
  17. =head1 DESCRIPTION
  18.  
  19. This program can be used to mirror a document from a WWW server.  The
  20. document is only transfered if the remote copy is newer than the local
  21. copy.  If the local copy is newer nothing happens.
  22.  
  23. Use the C<-v> option to print the version number of this program.
  24.  
  25. The timeout value specified with the C<-t> option.  The timeout value
  26. is the time that the program will wait for response from the remote
  27. server before it fails.  The default unit for the timeout value is
  28. seconds.  You might append "m" or "h" to the timeout value to make it
  29. minutes or hours, repectively.
  30.  
  31. Because this program is implemented using the LWP library, it only
  32. supports the protocols that LWP supports.
  33.  
  34. =head1 SEE ALSO
  35.  
  36. L<lwp-request>, L<LWP>
  37.  
  38. =head1 AUTHOR
  39.  
  40. Gisle Aas <aas@a.sn.no>
  41.  
  42. =cut
  43.  
  44.  
  45. use LWP::Simple;
  46. use Getopt::Std;
  47.  
  48. $0 =~ s,.*/,,;  # use basename only
  49.  
  50. $VERSION = sprintf("%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/);
  51.  
  52. $opt_h = undef;  # print usage
  53. $opt_v = undef;  # print version
  54. $opt_t = undef;  # timeout
  55.  
  56. unless (getopts("hvt:")) {
  57.     usage();
  58. }
  59.  
  60. if ($opt_v) {
  61.     require LWP;
  62.     my $DISTNAME = 'libwww-perl-' . LWP::Version();
  63.     die <<"EOT";
  64. This is lwp-mirror version $VERSION ($DISTNAME)
  65.  
  66. Copyright 1995-1996, Gisle Aas.
  67.  
  68. This program is free software; you can redistribute it and/or
  69. modify it under the same terms as Perl itself.
  70. EOT
  71. }
  72.  
  73. $url  = shift or usage();
  74. $file = shift or usage();
  75. usage() if $opt_h or @ARGV;
  76.  
  77. if (defined $opt_t) {
  78.     $opt_t =~ /^(\d+)([smh])?/;
  79.     die "$0: Illegal timeout value!\n" unless defined $1;
  80.     $timeout = $1;
  81.     $timeout *= 60   if ($2 eq "m");
  82.     $timeout *= 3600 if ($2 eq "h");
  83.     $LWP::Simple::ua->timeout($timeout);
  84. }
  85.  
  86. $rc = mirror($url, $file);
  87.  
  88. if ($rc == 304) {
  89.     print STDERR "$0: $file is up to date\n"
  90. } elsif (!is_success($rc)) {
  91.     print STDERR "$0: $rc ", status_message($rc), "   ($url)\n";
  92.     exit 1;
  93. }
  94. exit;
  95.  
  96.  
  97. sub usage
  98. {
  99.     die <<"EOT";
  100. Usage: $0 [-options] <url> <file>
  101.     -v           print version number of program
  102.     -t <timeout> Set timeout value
  103. EOT
  104. }
  105.