Question

I have a program that checks periodically for new files, and then process them.

Because I want to be safe that the file is not being copied over FTP, I move the file first.
The strange thing is that in Windows Server 2008 the file is moved, even when being copied, and the FTP copy operation ends in the new location.

How can this be possible?

I've tested the problem use this simple lines of code in a vbs file:

dim fso
set fso = createobject("Scripting.FileSystemObject")
fso.MoveFile "bigfile.zip", "moved\bigfile.zip"
Was it helpful?

Solution

Well, when you move a file (in the same drive), you're only telling the filesystem that the file can be found somewhere else, you're not actually moving any of the data around. So I'd guess that the move goes ahead and tells the filesystem where the file can now be found, but the FTP operation has already allocated space on the harddrive for the actual data and so the fact that the file has been moved, won't affect where the data is stored in any way, and so it all works.

If you moved the file to another drive I'd assume that something would break somewhere.

If you've got access to the client, you could have the client write another tiny file afterwards with the name bigfile.zip.complete or similar, and your server app could wait for that before beginning processing, that way you'd be sure that it's finished copying (this would also work in case the connection goes down halfway through and the client stops uploading the file even though it's not finished).

Or if you don't have access to the client, maybe you could try looking at the size of the file, if it hasn't changed in so many seconds or minutes, then it's hopefully finished.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top