my $self = shift; my $stations = shift; my @latestfiles = []; # remote host my $hostname = 'xxx.xxx.xxx.xxx'; my $username = 'xxxx'; my $password = 'xxxxxxxx'; my $Dbase = '/data/archive/real-time/staging/radial'; # time my ($sc,$mn,$hr,$md,$mo,$yr,$wd,$yd,$id) = localtime(time); $yr += 1900; $mo += 1; my $now = sprintf('%4d-%02d-%02d %02d:%02d:%02d',$yr,$mo,$md,$hr,$mn,$sc); # connect use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new( $hostname , user => $username , password => $password ) or fatal_error($!); # search foreach my $station ( @{$stations} ) { my $Dsearch = $Dbase.'/'. $station->{codename}.'/'.$yr; my @files = $sftp->find( $Dsearch , wanted => sub{ use Fcntl qw(S_ISREG); my $now = time(); my $yesterday = $now-(24*3600); my (undef, $entry) = @_; ( ($entry->{a}->mtime < $now) and ($entry->{a}->mtime > $yesterday) and S_ISREG($entry->{a}->perm) ) } ); push @latestfiles, $_->{filename} for $files[-1]; } $stations->{flatest} = \@latestfiles; my $template = $self->load_tmpl('show_radial_file_status.tmpl'); $template->param( title => "Latest Files on Simple Server", now => $now, hostname => $hostname, stations => $stations, ); $sftp->disconnect; return $template->output(); #return @latestfiles;