in reply to Re: Re: FTP and File Copying
in thread FTP and File Copying

There's no way. You cannot know if it's open. All you can do is quarantine any file touched in the last 15 minutes or so.

Some problems cannot be solved within the requirements specified.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Re: Re: FTP and File Copying
by Kanji (Parson) on Nov 27, 2000 at 13:17 UTC

    That isn't true if you broaden your toolset: utilities like fstat (on BSD), fuser (on Solaris), and lsof (on a wide variety of UNIX(ish) platforms, including the aforementioned) will all quite happily tell you whether a file is currently in use ...

    perl -wle '@open = qx|fstat $ARGV[0] 2>/dev/null|; print "YES" if $#open > 0' somefile

    (Error checking, and use strict;'ness left as an exercise to the reader. ;)

    Unfortunately, because all of those only give you a snapshot of how things looked, none of them are going to help tell whether a file is incomplete or allow you to easily deal with the race condition that follows testing (ie, what if someone resumes an incomplete upload?), but that may be a more acceptable margin of error depending on your circumstances.

    Another possibility lies with some of the more advanced (?) ftpd like NcFTPd, which supposedly support event reaction and/or notification. Theoretically, that means you could have the server kick off other processes when it thinks the files are finished uploaded instead of polling every half hour.

        --Kanji

    Update: D'oh! Didn't see Fastolfe's response before I wrote this ... that'll teach me to post before reading the entire thread.

Thanks to ALL
by Anonymous Monk on Nov 27, 2000 at 12:48 UTC
    Well I'd like to thank everyone for their input. I had rooted through various sources and didn't find any easy solutions and I was hoping there was an obviously easy one that I just couldn't put my finger on. It looks like even though I can get perl to make coffee for me in the morning, it's not going to grind the beans for me ;) It looks like suggestions are saying I'll have to do this from more of a OS based standpoint which is where I was thinking it was going to need to go. Thanks all... for all the feedback