![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how can i pick the latest log file as per below | mail2sant | Shell Programming and Scripting | 1 | 04-05-2008 05:29 AM |
| Read the latest file | wereyou | UNIX for Dummies Questions & Answers | 3 | 02-09-2008 09:12 PM |
| get latest file via ftp command | alx | Post Here to Contact Site Administrators and Moderators | 2 | 01-26-2006 08:44 AM |
| get latest file | inquirer | Shell Programming and Scripting | 3 | 07-06-2003 09:44 PM |
| How to Grab the latest file | n9ninchd | UNIX for Dummies Questions & Answers | 1 | 05-10-2001 01:31 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Getting latest file from ftp
Hi,
i have multile JAMA01.DAT.* files in my ftp. how can i get the latest file in from the ftp by executing the script Regards, Arun S |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Execute the below command
ls -ltr |
|
#3
|
|||
|
|||
|
hi Ganesh,
This wil display all the files listed in the ftp. but how can i get the latest file ??? Regards, Arun S |
|
#4
|
||||
|
||||
|
Quote:
Code:
#!/usr/bin/perl
use strict;
#use Data::Dumper;
use Net::FTP;
use Date::Parse;
my $site = 'localhost';
my $user = 'anonymous';
my $pass = 'nobody@localhost.com';
my $path = '/';
my $regex = '/\s+JAMA01\.DAT.*$/';
my $debug = 0;
my $ftp = Net::FTP->new($site, Debug => $debug)
or die "Cannot connect to some.host.name: $@";
$ftp->login($user, $pass)
or die "Cannot login ", $ftp->message;
$ftp->cwd($path)
or die "Cannot change working directory ", $ftp->message;
my (@items) = $ftp->dir()
or die "Cannot list directory ", $ftp->message;
my %files;
my $new_file;
my $new_ts=0;
for my $item (@items)
{
next unless($item =~ m/^-/); # only real files
next unless(grep($regex, $item));
my $ts;
my $file;
$item =~ m/\s+(\w+\s+\d+\s+\d+:\d+)\s+(.*)$/;
$ts = $1;
$file = $2;
if($ts)
{
$ts = str2time($ts);
}
else
{
warn("could not parse date on line:\n$item\n");
next;
}
$files{$file}=$ts;
$new_file = $ts > $new_ts ? $file : $new_file;
$new_ts = $ts > $new_ts ? $ts : $new_ts;
}
$ftp->get($new_file)
or die "get failed ", $ftp->message;
$ftp->quit;
|
||||
| Google The UNIX and Linux Forums |
| Tags |
| perl, perl regex, regex |
| Thread Tools | |
| Display Modes | |
|
|