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.