Determine when an FTP uploaded file is ready for p

2019-03-31 19:27发布

问题:

I want users to be able to upload files via FTP to my site (IIS 7.5). Once the file is uploaded, then I want to process the file using FileSystemWatcher. How can you determine when the file has completed uploading to the server? I don't want to process it before it completes the entire upload.

回答1:

There is really no inherent way that you can know the file has completed uploading. It is even possible that it is uploaded partially first and completed later.

You either need to determine from the file contents that it is a complete file or use some other marker. For example an empty file signifying completion, i.e. user first uploads file1.dat and then uploads file1.done to signal that file1.dat can now be processed.



回答2:

If you are using IIS 7.5 and above you can write an FTP provider that can kick off a process - this wouldn't use File System Watcher but probably provides a better alternative.

Here is a guide on IIS that shows an example (of sending an notification email in this case) that you can adapt to your purposes.

http://learn.iis.net/page.aspx/632/how-to-use-managed-code-c-to-create-an-ftp-provider-that-sends-an-email-when-files-are-uploaded/



回答3:

Actually you could check the file size every second and if it doesn't increase for a while maybe the transfer is ready.