Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stuck file with WinSCP script and OpenSSH on Windows 2000 Server

Posted on 2011-02-14
6
Medium Priority
?
947 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:Newbis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 27

Assisted Solution

by:BigRat
BigRat earned 400 total points
ID: 34895762
As a general principle I never delete data until it is REALLY old.

I had a similar problem recently. Someone unloaded and deleted data from one database into a file, transfered the file to a second machine which then loaded the data into another database. Every night. Naturally one night the data did not get into the second machine, on that night the processing was not performed, so the next night's data went in, overwriting the file, and got processed producing many errors because the previous night's data was missing.

So, the data will be unloaded BUT NOT deleted from the first machine. After the unload the data in the database will be marked as "transfered". We can undo this an re-export the data if things go wrong. The unload operation is not done on a per date basis, but all records which are not marked "transfered" are unloaded.

The file gets named with the date. It gets passed over to the other machine and loaded into the database. At the same time a record will be written with the date denoting a successful load. The processing will fail to start unless the latest date record is equal to yesterday's date (with alloances for Suindays and holidays). records are processed and marked as such they are not deleted. It is therefore possible to recover all the data at any time if anything goes wrong.

So in your case one starts by naming the file with today's date. It never gets deleted (except possibly at year's end and then all file which are older than say three months.
0
 
LVL 16

Assisted Solution

by:AlexPace
AlexPace earned 400 total points
ID: 34908761
It sounds like your script needs some error handling.

Have it check the result code and automatically retry the transfer if it fails.  If it fails again you could do some other operation to attempt to unlock it, maybe upload a junk file or change directories, or log out and back in, or something like that.  Then, if everything fails, have it send an email to alert of the problem so the next day's data doesn't overwrite like BigRat mentioned above.

I'm not sure if WinSCP script can do this but if not you could buy Robo-FTP to do it.
0
 

Author Comment

by:Newbis
ID: 34926863
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.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 27

Expert Comment

by:BigRat
ID: 34927791
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.
0
 

Accepted Solution

by:
Newbis earned 0 total points
ID: 35062758
I think the reason why it got "stuck" was that suddenly it need to accept hostkey (similar to http://winscp.net/forum/viewtopic.php?t=5883).  This appears to be what caused the problem, and I guess only error handling and alerting will solve that.
0
 

Author Closing Comment

by:Newbis
ID: 35115423
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Starting up a Project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question