3 # Simple mirror utility using LWP
7 lwp-mirror - Simple mirror utility
11 lwp-mirror [-v] [-t timeout] <url> <local file>
15 This program can be used to mirror a document from a WWW server. The
16 document is only transfered if the remote copy is newer than the local
17 copy. If the local copy is newer nothing happens.
19 Use the C<-v> option to print the version number of this program.
21 The timeout value specified with the C<-t> option. The timeout value
22 is the time that the program will wait for response from the remote
23 server before it fails. The default unit for the timeout value is
24 seconds. You might append "m" or "h" to the timeout value to make it
25 minutes or hours, respectively.
27 Because this program is implemented using the LWP library, it only
28 supports the protocols that LWP supports.
32 L<lwp-request>, L<LWP>
36 Gisle Aas <gisle@aas.no>
41 use LWP::Simple qw(mirror is_success status_message $ua);
45 $progname =~ s,.*/,,; # use basename only
46 $progname =~ s/\.\w*$//; #strip extension if any
50 $opt_h = undef; # print usage
51 $opt_v = undef; # print version
52 $opt_t = undef; # timeout
54 unless (getopts("hvt:")) {
60 my $DISTNAME = 'libwww-perl-' . LWP::Version();
62 This is lwp-mirror version $VERSION ($DISTNAME)
64 Copyright 1995-1999, Gisle Aas.
66 This program is free software; you can redistribute it and/or
67 modify it under the same terms as Perl itself.
71 $url = shift or usage();
72 $file = shift or usage();
73 usage() if $opt_h or @ARGV;
76 $opt_t =~ /^(\d+)([smh])?/;
77 die "$progname: Illegal timeout value!\n" unless defined $1;
79 $timeout *= 60 if ($2 eq "m");
80 $timeout *= 3600 if ($2 eq "h");
81 $ua->timeout($timeout);
84 $rc = mirror($url, $file);
87 print STDERR "$progname: $file is up to date\n"
89 elsif (!is_success($rc)) {
90 print STDERR "$progname: $rc ", status_message($rc), " ($url)\n";
99 Usage: $progname [-options] <url> <file>
100 -v print version number of program
101 -t <timeout> Set timeout value