.NET FtpWebRequest: how to check if a file is ready to download

I have a .NET service using FtpWebRequest to download images from an FTP server. I have a camera that stores images on a single FTP server.

If my service sees the image and tries to download it before the camera finishes saving the same image, the β€œnot yet saved part” of the image will appear grayed out (damaged).

Question: How to determine if an image is ready for upload (fully saved)?

+4
source share
3 answers

If you have control over the sending service, you must implement this using token files. If the transmitting service is, for example, write the file ".finished" when this is done, you can wait until this file appears.

However, I suspect that you have no control over the software in the camera. There are several problems with detecting whether the camera completed the download, especially when connecting to the Internet slowly.

I think the best solution would be to check for changes in file size. Browse the folder and see if new files appear. Then, if the file size has not changed, for example. per minute you should be safe enough to download the file.

+1
source

Make the camera software save images in a different directory (call Dir1). Try moving files from this directory to another directory (call Dir2 on it).

If the file is still opened by the camera software, the transition should fail, so only completed images will be moved from Dir1 to Dir2.

Download images from Dir2.

+1
source

Download another small file after the large file. Use a small file to check for "completeness" (or maybe MD5 inside it will work too).

0
source

All Articles