Hi Monks, I am trying to write a perl program to get the yesterday files from a ftp site. The program is working fine but i wanted to do some modifications in that and needed some help regarding that. The structure of the directories are -- Some directory say a/b/c/d inside that there are multiple folders like t1, t2,t3 and t4 . All the tridents directory contains hourly log files of everyday. My script is taking yesterday log files. I am facing two problems- 1. The script gets time out after an hour, i wanted it not to time out. 2. The logs get updated houly so the script remains in one directory itself say t1, it does not go to the other directory, i wanted to download parrelelly if possible or any other ways to download files from all directory. The script is --
#!/usr/bin/perl use Net::FTP; use Archive::Zip; use IO::File; use File::Spec; use File::Copy; print "Retrieving file from logs.com...\n"; $loginip = '1.2.3.4'; $loginid = 'loginid'; $loginpaswd = 'pswd'; ( $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 "SEC5TFLogs" ) { mkdir("SEC5TFLogs"); } if ( -d "SEC5TFLogs" ) { chdir("SEC5TFLogs"); } $ftp = Net::FTP->new( ($loginip), Debug => 0 ) or die "Cannot connect to logs.com: $@ \n"; $ftp->login( $loginid, $loginpaswd ) or die "Cannot login ", $ftp->message; $source_dir = "/a/b/c/d/"; print "Source Dir is $source_dir\n"; my @dir= $ftp->ls($source_dir); foreach $trident (@dir) { print "The tridents are $trident\n"; $ftp->cwd($trident) or die "Cannot change working directory ", $ftp-> +message; $ftp->binary || die "Unable to set mode to binary. ", $ftp->message; my $destinationDirectory = '\\\\1.15.1.40\E$\Sec5Logs'; my($vol,$dir,$tridentfile) = File::Spec->splitpath($trident); print "$tridentfile\n"; mkdir "$destinationDirectory/$tridentfile"; @list = $ftp->ls(); my ( $var1, $var2, $var3, $var4, $var5 ) = split( / /, scalar( localti +me( time - 86400 ) ) ); my $dateformat = "$var2$var3$var5"; print "Dateformat is $dateformat\n"; #printf "list = \n"; #print @list; foreach $file (@list) { if ( $file =~ /Trident..*$dateformat..*\.zip/i ) { $ftp->get($file) or die "get failed ", $ftp->message; printf "ftp done\n"; printf "Moving the file to 1.15.1.40 machine\n"; move("$file","$destinationDirectory/$tridentfile/$file"); printf "Moving of the file $file is done\n"; } print "The files are downloaded successfully\n"; closedir DIR; } $ftp->quit;

In reply to FTP to local machine by nt2282

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.