How can i ensure that i have received a file completely from an external source before reading it?Suppose i am receiving a file from an external source and i try to read the file before i have recieved the entire file.How can i ensure that this does not happen?
How to ensure that a file has been received completely before reading it?
Collapse
X
-
Tags: None
-
where are you getting it from?
depending on the download source, it might supply a checksum.
if you control the download source, then supply a checksum before you begin the file download (md5 for sha1)
then when the download has been inactive for 5 seconds, check the file against the checksum. If it matches, download is complete.
If it doesn't, then either the file is corrupted or download isn't complete yetComment
-
I guess i need to explain the situation a bit more.[:)]
I have this windows service running that polls certain folders for text and xml files received from an external source.Now the service should process only those files that have been received completely.Curr ently what is happening is that, whenever a huge file comes in the service tries to process it before it has been received completely.Ther e's no way to know the size or the contents of the file beforehand.Is there any way in which i can check if the file has been received completely?Comment
-
Hmm, you *might* be able to get away with trying to open the file for full read/write access, and saying don't share ANY access.
My theory is that if the file is not finished "arriving", then something will still have a handle open to it. So your request for full rights with no sharing would fail if something else has it open?
You could also poll for modified times and see when it's stopped changing for more then X amount of time?Comment
-
Comment