home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _8c94761d3c1d74734583993acedbaf81 < prev    next >
Text File  |  2004-06-01  |  3KB  |  122 lines

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