Yes, well... did you read the explaination of what the ls() method does?

Let me help you out....

$sftp->ls($remote [, $subref ]) Fetches a directory listing of $remote. If $subref is specified, for each entry in the directory, $subref will + be called and given a reference to a hash with three keys: filename, + the name of the entry in the directory listing; longname, an entry i +n a "long" listing like ls -l; and a, a Net::SFTP::Attributes object, + which contains the file attributes of the entry (atime, mtime, permi +ssions, etc.). If $subref is not specified, returns a list of directory entries, each + of which is a reference to a hash as described in the previous parag +raph.
So.... all you do is call ls() on your remote directory, and then test whether or not $subref->{'yourfile'} exists. If it does, download it - if it doesn't, um.. don't.

What about that can't be automated?

(PS. I may not have that usage exactly correct - but if you've been able to write the script in the first place, I'm sure you can figure out the correct usage)


In reply to Re^3: How to find whether a file is present on remote server? by McDarren
in thread How to find whether a file is present on remote server? by shilpam

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.