You probably get a damaged file, but to be sure, you need to
know how your FTP server deals with such a case. I don't know
any FTP server that does, but it is technically possible to write an FTP server that doesn't serve a file that is open for
writing. Or an FTP server could first try to lock a file - if
the modifying program locks before updating as well, you're sure the downloaded file isn't mangled.
However, none of this can be influenced by the downloading program. The client doesn't know about files being modified.
Abigail | [reply] |
The file will probably be corrupt. To solve such issues one option is to make a copy of a file to be downloaded in a safe and atomic manner, then download the copy. For example you might run a cron job to do the copy using flock locally on the server. Copying takes a finite quantum of time so you would typically use a rename strategy to make a file 'appear' in a given dir in an atomic fashion and avoid the race condition which occurs while you are writing the copy.
| [reply] |
What you could also do would be (if its within your control) have the application that is creating the file touch some sort of control file that would indicate when it is done writing the file. Your FTP could then look for the presence of that file and assume that the file you want is finished being written. Just another way to do it, as someone else mentioned, you can also have your script check the file size to make sure it has stopped growing.
What happens if something needs to write into a file after you have started downloading it but are not yet done downloading the file? | [reply] |
Check the file sizes once every 10 seconds for say, 30 seconds. Unless it's a file that's intermitently opened and closed, this could work in a local setting.
| [reply] |
Check out flock for more information on this. flock will try to lock a file. It will fail if it can't, meaning the file is in use or otherwise inaccessible.
Edit: As Abigail-II pointed out, this won't really help you over FTP. I should've read your question more thoroughly, but flock is a place to start. | [reply] |
Check out flock for more information on this. flock will try to lock a file.
Unfortunally, you can't lock a file over FTP. Technically, you can write an FTP server that flocks files, but that's done at the server side, not the client side.
Abigail
| [reply] |