3 |
# Use try to connect to a FTP server using Net::FTP, login as |
# Use try to connect to a FTP server using Net::FTP, login as |
4 |
# anonymous and issue PWD. |
# anonymous and issue PWD. |
5 |
# |
# |
6 |
|
# Since anonymous ftp servers can be quite busy I suggest that you |
7 |
|
# enter more than one anonymous ftp server and use option -o. That will |
8 |
|
# return success if ANY OF SERVERS are available -- that way you can |
9 |
|
# test if you can connect to ANY ftp server outside. |
10 |
|
# |
11 |
# For use with "mon". |
# For use with "mon". |
12 |
# |
# |
13 |
# Arguments are "-p port -t timeout host [host...]" |
# Arguments are "[-p port] [-t timeout] [-o] host [host...]" |
14 |
# |
# |
15 |
# 2002-09-02 Dobrica Pavlinusic <dpavlin@rot13.org> |
# 2002-09-02 Dobrica Pavlinusic <dpavlin@rot13.org> |
16 |
# |
# |
18 |
use Getopt::Std; |
use Getopt::Std; |
19 |
use Net::FTP; |
use Net::FTP; |
20 |
|
|
21 |
getopts ("p:t:"); |
getopts ("p:t:o"); |
22 |
$PORT = $opt_p || 21; |
$PORT = $opt_p || 21; |
23 |
$TIMEOUT = $opt_t || 30; |
$TIMEOUT = $opt_t || 30; |
24 |
|
|
29 |
my $result = check_anon_ftp($host); |
my $result = check_anon_ftp($host); |
30 |
if ($result) { |
if ($result) { |
31 |
$bad{$host} = $result; |
$bad{$host} = $result; |
32 |
|
} else { |
33 |
|
$good{$host} = "ok"; |
34 |
} |
} |
35 |
} |
} |
36 |
|
|
44 |
print "HOST $h: " . $bad{$h}, "\n"; |
print "HOST $h: " . $bad{$h}, "\n"; |
45 |
} |
} |
46 |
|
|
47 |
|
if ($opt_o && keys %good > 0) { |
48 |
|
# one host is o.k., don't report warning |
49 |
|
exit 0; |
50 |
|
} |
51 |
|
|
52 |
exit 1; |
exit 1; |
53 |
|
|
54 |
sub check_anon_ftp { |
sub check_anon_ftp { |