namishtiwari has asked for the wisdom of the Perl Monks concerning the following question:
I want o campare if it is todays files and time is 2358 then only it should be allowed to be ftp'ed else let it be in the server. I am pasting my code here....arident16_Jul282009_2358.zip arident16_Jul282009_2320.zip arident16_Jul272009_1619.zip
Thanks NT#!/usr/bin/perl use Net::FTP; use Archive::Zip; use IO::File ; print "Retrieving file from abc.com...\n"; $loginip='12.34.56.78'; $loginid='login'; $loginpaswd='password'; ($sec,$min,$hour,$mday,$mon,$year)=(localtime(time))[0,1,2,3,4,5]; $time_stamp= "_" . (1900+$year) . "_" . ($mon+1) . "_" . ($mday) . "_" + . $hour . "_" . $min . "_". $sec; printf "time stamp = $time_stamp\n"; unless(-d "TFLogs") { mkdir("TFLogs"); } if( -d "TFLogs") { chdir("TFLogs"); } $ftp = Net::FTP->new(($loginip), Debug => 0) or die "Cannot connect to abc.com: $@ \n"; $ftp->login($loginid,$loginpaswd) or die "Cannot login ", $ftp->message; $source_dir="nt12/logs/"; $ftp->cwd($source_dir) or die "Cannot change working directory ", $ftp->message; $ftp->binary || die "Unable to set mode to binary. ", $ftp->message; @list=$ftp->ls(); printf "list = \n"; print @list; foreach $file (@list) { <quote> i want to fit in my code here to check for the latest file and time. </quote> $ftp->get($file) or die "get failed ", $ftp->message; my $zipname = $file; my $destinationDirectory = 'C:\Perl Script\TFLogs'; my $zip = Archive::Zip->new($zipname); foreach my $member ($zip->members) { next if $member->isDirectory; (my $extractName = $member->fileName) =~ s{.*/}{}; $member->extractToFileNamed( "$destinationDirectory/$extractName"); } } $ftp->quit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date in required format
by FalseVinylShrub (Chaplain) on Jul 29, 2009 at 16:03 UTC | |
by Anonymous Monk on Jul 30, 2009 at 09:18 UTC | |
by namishtiwari (Acolyte) on Jul 30, 2009 at 09:29 UTC | |
by namishtiwari (Acolyte) on Jul 30, 2009 at 09:45 UTC | |
by namishtiwari (Acolyte) on Jul 30, 2009 at 09:11 UTC | |
|
Re: date in required format
by psini (Deacon) on Jul 29, 2009 at 15:33 UTC |