Stuck file with WinSCP script and OpenSSH on Windows 2000 Server
Posted on 2011-02-14
A company I do some business with has a WinSCP script that uploads a file nightly using SFTP, overwriting it if it's there. They also have another similar script that transfers the file to a different server and deletes the original file. (I think the machines are running Windows 2000 Server, with OpenSSH to provide SFTP functionality.)
Unfortunately, at some point, Windows said that the file was in use, and it couldn't be deleted. Attempting to delete it manually gave a File In Use error. Hence, both scripts failed to function properly.
However, after I ran a WinSCP script to upload the file with a different name, the lock on the original file was mysteriously removed, and I was able to delete any remnants of the file.
Therefore, I suspect that WinSCP or OpenSSH somehow had a handle to the file that was released by running another WinSCP script successfully.
This is the first time that happened with these scripts, which had been running for years without ever encountering this specific problem before. Nevertheless, I would be interested in any ideas about how to prevent this sort of thing in the future. Obviously, one could have a script that keeps changing the filename (e.g., appending 1, 2...) if it gets a "file in use" error. But I wonder if there's a simpler or more elegant/direct way.