Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to update a file on a server every fifteen or so minutes. This involves a file copy from an authoring site on to the server.

Occasionally (And with a lot of bad luck) the .Net application that serves the file reads it at a period in time when the file is being overwritten and therefore reads in an empty file. The problem is compounded because for performance reasons the file is cached for up to 15 minutes.

Is there anyway in Windows to minimise the possibility of the file being blank? i.e. is there a way to copy the contents into the file but not "commit" them to the file system until its fully written?

The file is copied using SSH/FTP as its on a non-domain box within the DMZ and hosted on Windows 2008 R1 machines.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The usual solution is to upload using a temporary name and rename when upload complete.

share|improve this answer
    
... which relies for proper operation upon atomic renaming semantics that Win32 doesn't have. The Win32 solution then becomes to delete/rename out of the way the existing file just before renaming its replacement in place (retrying until the file has no open handles and it can be deleted/renamed), thereby leaving a window where no file by the desired name exists at all. –  JdeBP Jun 8 '11 at 13:54
    
@JdeBP: Perhaps the .Net application can be coded to handle this (if file ! exists sleep 10 ms and try again, quit after n fails) –  RedGrittyBrick Jun 8 '11 at 14:00
2  
According to a stackoverflow question "In Windows Vista and Windows Server 2008 an atomic move function has been added - MoveFileTransacted()" - maybe someday some sftpd implementation will use it? –  RedGrittyBrick Jun 8 '11 at 14:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.