Determine when an FTP uploaded file is ready for processing using FileSystemWatcher

亡梦爱人 提交于 2019-12-03 20:32:46

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.

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/

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!