Topic "Safe deletion on remote server"

Author Message


Thanks for a great application!

I need to use windows scheduler to get all files in a mailbox-directory on a remote server, check if "get" was flawless, and then delete the downloaded files on the remote server. The process is repeated every 15 minutes. This can be done using .bat files and a winSCP-script.

BUT, a nasty situation can arise: E.g. 10 files are found in the remote directory. All 10 files are downloaded. While in process of downloading a new file, #11, is posted in the remote derectory (by an automatic process on the remote host - needless and complicated to explain here). If I delete all files in the remote directory, then only 10 files are moved to the local server. File #11 will be deleted without being downloaded.

Any way to avoid this using WinSCP?

Michael Bruus
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24755
Location: Prague, Czechia
Move the remote files to another remote directory and download and delete them only from there.
Martin Prikryl


This is well after the fact but thought I'd put it out here in case someone has a similar problem.
I need to do something very similar to what Michael describes but don't have rights to create directories on the remote server.

In my case, file names are well defined such as I need to pick up pickup*.txt (and I'll be dropping off files named like droppedoff*.txt which I can ignore). I do a mv to a new name format such as a new extension and in the get can switch the destination extension back so my local files are the expected extension still.

mv pickup*.txt pickup*.get
get pickup*.get pickup*.txt
rm pickup*.get

Assuming the other end is always putting pickup files with .txt extensions and never .get extensions (in other words I always control what is named .get) then only items at the time of the mv will be dealt with on the get and the rm and any new files during my connection will be .txt and ready for the next time I run the script.

This at least handle doing the get and the rm to the same set of files.

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License