Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.5 KiB

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