Delete files on remote server

Advertisement

Guest

Delete files on remote server

Hello I have written the following script to get files from the remote server and copy them to our local server, this is working fine. Now I want to also get the files on the remote server after they have been copied, but my get -delete isn't working, could someone help me modify my script please.
# Connect
open sftp:...
 
# Change remote directory
cd /SA223/PHI/RWB
 
# Download file to the local directory A:\Shares\Ochin-ReportingWorkBench
get * A:\Shares\Ochin-ReportingWorkBench\
 
# Delete Remote Files (here is the problem)
get -delete * .\
 
# Disconnect
close
 
# Exit WinSCP
exit

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: delete files on remote server

I'm not sure what you mean by "get the files on the remote server". Did you mean "delete"?
You might be looking for this:
get -delete * A:\Shares\Ochin-ReportingWorkBench\
(i.e. add the -delete to your first get command)

Reply with quote

Moaen
Guest

How to automate downloading and deleting files form remote server

Hi,
I am using Keep Local Directory to update function to watch for the changes on the remote directory and reflect them to the local drive.

Under the options, I clicked on Delete files. But the files still appears on the remote server after the download.

Am I doing something wrong?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: How to automate downloading and deleting files form remote server

@Moaen: The option is to synchronize removal of the remote files to the local directory. So it does not do what you want.

If you want to remove the new files from the remote directory, you will have to modify the code. Quick solution is to add this after the $difference.Resolve call, when the action is DownloadNew (or DownloadUpdate, although it should not occur in your set up):
$session.RemoveFile($difference.Remote.FileName)

Reply with quote

Advertisement

You can post new topics in this forum