Link to home
Start Free TrialLog in
Avatar of Newbis
Newbis

asked on

Stuck file with WinSCP script and OpenSSH on Windows 2000 Server

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.
SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Newbis
Newbis

ASKER

Thanks for the comments.  My situation is actually a bit different from BigRat's.  The file only gets deleted after it is copied; if for some reason it got deleted when it shouldn't, that wouldn't be a big deal...nothing would get lost that doesn't exist somewhere else.  Mainly, it must be deleted because even though there's no anonymous access to the directory and only authorized users can get it, we still don't want to have the data lying around when it doesn't need to be there.  As I mentioned, I could of course put in some error-handling if they want me to spend time with it.  Mainly, I just want to understand how and why the file got into a state where it couldn't be deleted (apparently related to WinSCP or the local SFTP server program having continuous "use" of it?) and whether that can be prevented in the first place.
We have had similar situations where a process has disappeared (perhaps died, at least you can't find it) leaving files open. Obviously by rebooting every day reduces the risk, but many of our customers don't daily reboot.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Newbis

ASKER

I found what was likely causing WinSCP to cause the file to have an open handle to it.  My intention in asking the question was to figure out what was the causing the problem and potentially how to prevent that, not just how to make the solution more robust in case there's a problem, which I know also needs to be done.