Testing for complete uploaded file

Peter Hansen peter at engcorp.com
Mon May 26 10:14:32 EDT 2003


Carsten Gehling wrote:
> 
> A user uploads to my server with ftp.
> 
> I'm writing a "daemon" to process those files. I do this by checking for new
> files in the upload folder, process them, and finally delete them. This is
> all done in a loop, that pauses for a few seconds between each check.
> 
> However since some of the files takes maybe a few minutes to upload, I only
> want to process them AFTER the upload os complete.
> 
> I thought that the files might be write-protected during upload, and that I
> therefore could use:
>         try: ftest = open(uploaded_filename, "w")
>         except: return
>         else: ftest.close()
> 
> but they are not. The above call to open() does not generate an exception
> even if the file is still being uploaded.
> 
> What should I do instead?

Scan periodically and consider a file to be fully uploaded only once its
size stops changing?  (With appropriate extra delays for safety.)

Or check a log file to see when a file upload has completed.

Or use an FTP server written in Python, and modify it to notify the
daemon when the upload has completed.

-Peter




More information about the Python-list mailing list