Lock a file for reading when uploading it to FTP
-
Hello all, I am having a bit o problem and i need a simple, elegant fix. The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped. Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped. So far, my solutions do not work fully or are very very ... ugly:D Thx
-
Hello all, I am having a bit o problem and i need a simple, elegant fix. The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped. Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped. So far, my solutions do not work fully or are very very ... ugly:D Thx
-
Hello all, I am having a bit o problem and i need a simple, elegant fix. The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped. Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped. So far, my solutions do not work fully or are very very ... ugly:D Thx
How does the consumer process know there is a file to process? And does the consumer use FTP to download the file, or is it on the machine your producer is uploading to? :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
How does the consumer process know there is a file to process? And does the consumer use FTP to download the file, or is it on the machine your producer is uploading to? :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
The consumer searches the ftp for a list of files with a given extension. (but it can also grab all the files from ftp, regardless of the extension. This part is configurable)
Here are some ways to consider: 1. have the consumer wait for a signal, and once it receives the signal make a list of available files, then signal back to the producer; in between the consumer should not start creating new files. 2. have the producer use a fake extension, and once the file is uploaded, have it rename the extension; 3. have the producer a file, and once the file is uploaded, have it signal the consumer while mentioning the file name. As for signal, you could use anything available, including the creation and deletion of a file that simply contains a filename. My favorite would be 3, i.e. producer creates a file say file1.ext1, then it creates file "currenttime.signal" containing the text "file1.ext1"; consumer would find all signal files, read them, delete them, and process the file mentioned in them. And I would use yyyyMMdd_HHmmss format for currenttime, so the signal files have identical alphabetical and chronological order. PS: if you are afraid two files need could be generated in the same second, just add a 2-second delay in the producer code! :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
Here are some ways to consider: 1. have the consumer wait for a signal, and once it receives the signal make a list of available files, then signal back to the producer; in between the consumer should not start creating new files. 2. have the producer use a fake extension, and once the file is uploaded, have it rename the extension; 3. have the producer a file, and once the file is uploaded, have it signal the consumer while mentioning the file name. As for signal, you could use anything available, including the creation and deletion of a file that simply contains a filename. My favorite would be 3, i.e. producer creates a file say file1.ext1, then it creates file "currenttime.signal" containing the text "file1.ext1"; consumer would find all signal files, read them, delete them, and process the file mentioned in them. And I would use yyyyMMdd_HHmmss format for currenttime, so the signal files have identical alphabetical and chronological order. PS: if you are afraid two files need could be generated in the same second, just add a 2-second delay in the producer code! :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
Thanks Luc. The signal idea has crossed my mind, but not in such a superb manner:). I was afraid i would have to modify quite a lot, and that is not far from truth. I retrospective, the whole architecture of the program should be reconsidered:D. Hopefully i'll have the time to do just that, and then i will implement your solution. Thx all.
-
Thanks Luc. The signal idea has crossed my mind, but not in such a superb manner:). I was afraid i would have to modify quite a lot, and that is not far from truth. I retrospective, the whole architecture of the program should be reconsidered:D. Hopefully i'll have the time to do just that, and then i will implement your solution. Thx all.