Try locking the file with flock. With any luck, your sftp daemon software has obtained a lock on the file while it's writing to it. You can either have flock block so that your program pauses and resumes when the file is finished uploading or not block flock (I just like saying that) and have your program immediately abort (or go back to sleep or whatever) to try again later. Typical usage:
$lockOK = flock($filehandle,2); # Resumes program flow when you obta +ined the lock # or $lockOK = flock($filehandle,6); # Check return value to see if you w +ere able to lock the file # ..... flock($filehandle,8); # Release lock when done
If for some bizarre reason the SFTP upload process doesn't bother locking the files it's writing to, you should email the author of that daemon to suggest it.
Edit: Crap, it seems you're correct mr salva, sftp (and even the ancient 'ftp') don't bother flocking at all. I downloaded the source for the latest version of openssh I could find (4.6), and grepped for 'flock', and it would seem it never uses it. This solution is useless for your purpose then, unless you have a better SFTP daemon than OpenSSH.

In reply to Re: Monitor Folder, Wait for Upload? by saintly
in thread Monitor Folder, Wait for Upload? by ecuguru

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.