#!/usr/bin/perl ### ### CHECKFTP.PL ### (c) 2003 Software Poetry, Inc. ### http://www.softwarepoetry.com/webob ### ### Verify that an FTP site is alive and, optionally, see if a particular ### file has been updated. Requires Net::FTP. ### ### For simplicity this file hard-codes configuration information. You can ### just edit the values or needed, or convert the script to use @ARGV ### so that you can use it on multiple sites. ### ### Define c_szFile as the empty string if you just want to verify ### connectivity. Define c_csecUpdateInterval to 0 if you just want to ### verify that the file exists rather than check its modification time. ### ### License: This software is provided as-is with NO WARRANTY WHATSOEVER. ### Software Poetry makes no claims as to its fitness for any purpose. ### This file and any derivatives or translations of it may be freely ### copied and redistributed so long as the original license and copyright ### notices are included and not altered. ### use strict; use Net::FTP; use Time::Local; # +------------------------------------------------------------------------- # | Configuration Variables # +------------------------------------------------------------------------- my $c_szHost = "weather.noaa.gov"; my $c_szLogin = "anonymous"; my $c_szPassword = 'anonymous@anonymous.com'; # set to non-empty to verify existence of a file my $c_szFile = "/data/observations/state_roundup/wa/waz001.txt"; # set to non-zero to verify age of file (err if > the interval given) my $c_csecUpdateInterval = (60 * 60 * 12); # 12 hours worth of seconds # +------------------------------------------------------------------------- # | Entrypoint # +------------------------------------------------------------------------- my $ftp; my $timeModified; my $timeNow; if (!($ftp = Net::FTP->new($c_szHost))) { print "$@\n"; exit(1); } if (!($ftp->login($c_szLogin, $c_szPassword))) { print "login failed\n"; $ftp->quit; exit(2); } if ($c_szFile ne "") { if (!($timeModified = $ftp->mdtm($c_szFile))) { print "file not found\n"; $ftp->quit; exit(3); } if ($c_csecUpdateInterval != 0) { my $csecDiff = time() - $timeModified; if ($csecDiff > $c_csecUpdateInterval) { print "file out of date\n"; exit(4); } } } $ftp->quit; exit(0);