home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _d73ebdf0d6e2064521b4cfa31bbdd1c2 < prev    next >
Text File  |  2000-03-23  |  3KB  |  105 lines

  1. #!perl -w
  2.  
  3. # $Id: lwp-mirror.PL,v 1.19 1999/09/15 19:42:19 gisle Exp $
  4. #
  5. # Simple mirror utility using LWP
  6.  
  7. =head1 NAME
  8.  
  9. lwp-mirror - Simple mirror utility for WWW
  10.  
  11. =head1 SYNOPSIS
  12.  
  13.  lwp-mirror [-v] [-t timeout] <url> <local file>
  14.  
  15. =head1 DESCRIPTION
  16.  
  17. This program can be used to mirror a document from a WWW server.  The
  18. document is only transfered if the remote copy is newer than the local
  19. copy.  If the local copy is newer nothing happens.
  20.  
  21. Use the C<-v> option to print the version number of this program.
  22.  
  23. The timeout value specified with the C<-t> option.  The timeout value
  24. is the time that the program will wait for response from the remote
  25. server before it fails.  The default unit for the timeout value is
  26. seconds.  You might append "m" or "h" to the timeout value to make it
  27. minutes or hours, repectively.
  28.  
  29. Because this program is implemented using the LWP library, it only
  30. supports the protocols that LWP supports.
  31.  
  32. =head1 SEE ALSO
  33.  
  34. L<lwp-request>, L<LWP>
  35.  
  36. =head1 AUTHOR
  37.  
  38. Gisle Aas <gisle@aas.no>
  39.  
  40. =cut
  41.  
  42.  
  43. use LWP::Simple qw(mirror is_success status_message $ua);
  44. use Getopt::Std;
  45.  
  46. $progname = $0;
  47. $progname =~ s,.*/,,;  # use basename only
  48. $progname =~ s/\.\w*$//; #strip extension if any
  49.  
  50. $VERSION = sprintf("%d.%02d", q$Revision: 1.19 $ =~ /(\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-1999, 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 "$progname: 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.     $ua->timeout($timeout);
  84. }
  85.  
  86. $rc = mirror($url, $file);
  87.  
  88. if ($rc == 304) {
  89.     print STDERR "$progname: $file is up to date\n"
  90. } elsif (!is_success($rc)) {
  91.     print STDERR "$progname: $rc ", status_message($rc), "   ($url)\n";
  92.     exit 1;
  93. }
  94. exit;
  95.  
  96.  
  97. sub usage
  98. {
  99.     die <<"EOT";
  100. Usage: $progname [-options] <url> <file>
  101.     -v           print version number of program
  102.     -t <timeout> Set timeout value
  103. EOT
  104. }
  105.