3 # Based on an ftp client found in the LWP Cookbook and
4 # revised by Nathan V. Patwardhan <nvp@ora.com>.
6 # Copyright 1997 O'Reilly and Associates
7 # This package may be copied under the same terms as Perl itself.
9 # Code appears in the Unix version of the Perl Resource Kit
14 my $ua = new LWP::UserAgent;
16 # check to see if a JDK port exists for the OS. i'd say
17 # that we should use solaris by default, but a 9meg tarfile
18 # is a hard pill to swallow if it won't work for somebody. :-)
19 my $os_type = $^O; my $URL = lookup_jdk_port($os_type);
20 die("No JDK port found. Contact your vendor for details. Exiting.\n")
23 print "A JDK port for your OS has been found.\nContacting: ".$URL."\n";
25 # Now, parse the URL using URI::URL
26 my($jdk_file) = (url($URL)->crack)[5];
27 $jdk_file =~ /(.+)\/(.+)/; $jdk_file = $2;
29 print "Attempting to download: $jdk_file\n";
32 my $bytes_received = 0;
34 open(OUT, ">".$jdk_file) or die("Can't open $jdk_file: $!");
35 $ua->request(HTTP::Request->new('GET', $URL),
37 my($chunk, $res) = @_;
39 $bytes_received += length($chunk);
40 unless (defined $expected_length) {
41 $expected_length = $res->content_length || 0;
43 if ($expected_length) {
44 printf STDERR "%d%% - ",
45 100 * $bytes_received / $expected_length;
47 print STDERR "$bytes_received bytes received\n";
56 my $jdk_hosts = 'jdk_hosts';
59 open(CFG, $jdk_hosts) or die("hosts error: $!");
62 ($os, $host) = split(/\s*=>\s*/, $_);
63 next unless $os eq $port_os;
68 return "" unless @HOSTS;
69 return $HOSTS[rand @HOSTS]; # Pick one at random.