Hi Monks!

I am downloading files using ftp,but sometimes someone drops files in there that shouldn’t be in there, like other file types and files with "0" size, I have no control over this. I am looking for files ending with .xml only and check if the file is new to prevent duplications of files been downloaded, need to check if file size is greater than 0. I am trying to do this in one IF statement but for some reason my code is ignoring the checks, can some one take a look at it and let me know if this is the OK method or if there is any better way of doing it?

Here is the part of my code that does this:

my @files=$ftp->ls or die "Cannot list current directory: $@"; foreach my $x_files(@files) { # Tried that but it exits completely and never gets to the next if #next unless ($file_path.$x_files =~ m/\.xml$/); #I am loking for new files only, it works for new files only but ignor +es the rest of the check, has to be a better way here if ((-e $file_path.$x_files ) && (-z $file_path.$x_files > 0) && ($ +file_path.$x_files =~ m/\.xml$/) ) { # Print this just for sanity check! print "File $x_files already exists!<br>"; print "File $x_files has ) size!<br>"; print "File $x_files isn't a xml file!<br>"; }else{ $ftp->get($x_files, "$file_path".$x_files) or die "Can't fetch $x_files: $ +!\n"; push @all_files, "$file_path".$x_files; + } #print "$x_files<br>"; } $ftp->quit;


Thanks for the help!

In reply to File Size Check by Anonymous Monk

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.