Wednesday, September 29, 2010

Get public advisories from the National Hurricane Center

# Download the public advisory from National Hurricane Center

use strict;
use warnings;

use Net::FTP;

my $FtpServer = '';
my $RemoteDir = '/pub/products/nhc/public';
my $LocalFileName = '/home/janeiros/chk/txt/nhc.txt';

# Get the modification time of the local file
my $LocalFileMDTM = (stat($LocalFileName))[9];

my $Ftp = Net::FTP->new($FtpServer, Passive => 1, Debug => 0)
        or die "Couldn't no connect to $FtpServer: $!\n";

$Ftp->login('anonymous', '')
        or die "Couldn't logon to $FtpServer: $!\n";



# Get the file name of the last advisory
my $RemoteFileName = ($Ftp->ls())[-1];

# Get the last modification time for the remote file
my $RemoteFileMDTM = $Ftp->mdtm($RemoteFileName);

# Get the file only if it is older than the local
if (!defined($LocalFileMDTM) || $RemoteFileMDTM > $LocalFileMDTM) {
        $Ftp->get($RemoteFileName, $LocalFileName);



No comments: