[TriLUG] Scripting & C++ question

T. Bryan tbryan at python.net
Sat Nov 12 10:09:56 EST 2005


On Friday 11 November 2005 17:50, Mark Freeze wrote:
> Hmmm ...  good point.  I don't think I'll ever have this situation,
> but it's good to know.  I am trying to convert all of my programs away
> from VB and Visual FoxPro.  One of the features in VB.Net that I am
> trying to imitate is the FileSystemWatcher Component that will 'watch'
> a certain directory and then take action when a file shows up.

I've never used it myself, but if you know that it will be available on the 
Linux machines where your code will run, you might want to look into FAM.
http://oss.sgi.com/projects/fam/index.html

> My situation is that I want to monitor an incoming ftp directory and
> process files as they complete the upload.
....
> My next challenge, which was discussed a couple of months ago, but I
> still don't have a good handle on, is how to monitor the directory for
> the files and know that the ftp session had ended, indicating that all
> of the files are uploaded.  

Well, again, if you aren't writing some general purpose code that has to run 
everywhere, you may be able to lean on the FTP daemon here.  I believe 
ProFTPD, for example, either does this natively or with a freely-available 
extension.  The ftp process transfers files into a separate directory or 
something until the FTP transfer is complete.  Then it moves the file into 
the incoming FTP directory.

If you can't rely on a particular FTP daemon, and you cannot have your clients 
upload a marker file or something at the end of each upload so that you can 
detect the end of the upload, then you'll probably have to poll the incoming 
FTP directories.  You code would scan the directories, remember all of the 
files' mod times, and then sleep for the length of the FTP daemon's timeout.  
That is, if the FTP daemon times out idle connections after 10 minutes, then 
you poll every ten minutes.  If the mod time on a file has not changed the 
next time you look at it, either the FTP upload is complete, or the client 
got timed out.  

Good luck, 
---Tom




More information about the TriLUG mailing list