+1  A: 

EOF is simply C++'s way of telling you there is no more data. There's no EOF "character" that you can use to check if the file is completely written.

The way this is typically accomplished is to transfer the file over with one name, i.e. myfile.txt.transferring, and once the transfer is complete, move the file on the target host (back to something like myfile.txt). You could do the same by using separate directories.

Billy ONeal
thanks did not know that
Pedantically, there *is* an EOF character (Ctrl-D was standard, Windows used Ctrl-Z) but it was only ever used in text files and isn't even used anymore as far as I know.
dash-tom-bang
@dash-tom-bang: There is an ASCII "EOF" character, yes, but that's not what `std::istream::eof` is checking for ;)
Billy ONeal
A: 

In C, and I think it's the same in C++, EOF is not a character; it is a condition a file is (or is not) in. Just like media removed or network down is not a character.

pmg
A: 

All finite files have an end. If a file is being written by one process, and (assuming the OS allows it) simultaneously read (faster than it is being written) by another process,then the reading process will see an EOF when it has read all the characters that have been written.

What would probably work better is, if you can determine a length of time during which you can guarantee that you'll receive a significant number of bytes and write them to a file (beware OS buffering), then you can walk the directory once per period, and any file that has changed its file size can be considered to be unfinished.

Another approach would require OS support: check what files are open by the receiving process, with a tool like lsof. Any file open by the receiver is unfinished.

Mike DeSimone
Yeps, I could verify the size of the file and test whether it is growing. But suppose the size stalls for some reason and then I verify and see that the size is still the same. I will then make the wrong assumption that the file is complete which might not be true.
Then you're stuck with the second solution: watch the process and see what files it has open.
Mike DeSimone
Ok I will have to see if I could on Windows Server to watch whether the file is still open and is being written.
Perhaps, I could try with the c++ is_open() and determine if a file is already open
@user: No, that just tells you if the stream is associated with a file, not if another process has the file open.
Billy ONeal
A: 

Neither C nor C++ have a standard way to determine if the file is still open for writing by another process. We have a similar situation: a server that sends us files and we have to pick them up and handle as soon as possible. For that we use Linux's inotify subsystem, with a watch configured for IN_CLOSE_WRITE events (file was closed after having been opened for writing), which is wrapped in boost::asio::posix::stream_descriptor for convenient asynchronicity.

Depending on the OS, you may have a similar facility. Or just lsof as already suggested.

Cubbi
I will try to write a program using inotify hoping that I will not run into trouble with the buffer.