
yahhodeol
Novice
Apr 2, 2010, 3:52 PM
Post #7 of 8
(411 views)
|
|
Re: [7stud] get latest file using Net::FTP
[In reply to]
|
Can't Post
|
|
I am looking to match string(date part in file name) with output from localtime() function. This is for testing that i have printed (print "$stra $strb $strc\n";) instead of doing ftp. I am getting output($stra $strb $strc) of all lines even it's in the if condition. Below is the updated script.#!/usr/bin/perl use Net::FTP; use Date::Format; my $host="www.com"; my $directory="/path/to/files"; $ftp=Net::FTP->new($host,Timeout=>240) or $newerr=1; push @ERRORS, "Can't ftp to $host: $!\n" if $newerr; myerr() if $newerr; print "Connected\n"; $ftp->login("username","password") or $newerr=1; print "Getting file list"; push @ERRORS, "Can't login to $host: $!\n" if $newerr; $ftp->quit if $newerr; myerr() if $newerr; print "Logged in\n"; $ftp->cwd($directory) or $newerr=1; push @ERRORS, "Can't cd $!\n" if $newerr; myerr() if $newerr; $ftp->quit if $newerr; @files=$ftp->dir or $newerr=1; push @ERRORS, "Can't get file list $!\n" if $newerr; myerr() if $newerr; print "Got file list\n"; $ftp->quit; my $timing = time2str("%Y %m %d", time); print "$timing\n"; foreach(@files) { $_=substr($_,41); s/ */ /g; s/^ *//g; chomp; @stuff=split / /; my $stra = substr($stuff[4],13,4); my $strb = substr($stuff[4],18,2); my $strc = substr($stuff[4],21,2); if(($stra == $timing[0]) && ($strb == $timing[1]) && ($strc == $timing[2])) { print "$stra $strb $strc\n"; } } sub myerr { print "Error: \n"; print @ERRORS; exit 0; }
Now, if i remove if condition and type only, print "$stra $strb $strc\n"; print "$timing[0] $timing[1] $timing[2]"; I am getting right output: attached file(ftp_test.doc) I am making some mistake while comparing them. I guess data type. Please correct me. Thanks
(This post was edited by yahhodeol on Apr 3, 2010, 1:32 PM)
|