Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

vladimir_andrei

Re: Delete a remote file after successful sync

Thanks, it worked very well.
vladimir_andrei

Delete a remote file after successful sync

Can you please tell me how can I proceed in this case?

Thank you in advance and have a nice day!
vladimir_andrei

Delete a remote file after successful sync

Hi there,

I want to sync a local source with a remote root destination. After the files are successfully synchronized I want to delete a specific file from remote destination: lock.pid.
I have some large files for which the synchronization takes some time, so I thought I would add a file to delete after the copy is done successfully.
I have the following batch script:

option batch abort
option confirm off
option echo off
option transfer binary
 
open sftp://user@host -privatekey="D:\folder\key.ppk" -hostkey="ssh-xxxxxxxxxxxxxxxxxxxxx"
 
synchronize remote source -delete="lock.pid"
 
close


The synchronization works, but after that lock.pid still on remote server
Guest

Re: how to synchronize files from local to remote and delete local files in winscp

Thanks Martin, it worked.
put -delete SOURCE DESTINATION

I was trying to use both synchronize, put and delete at the same time, that's why it was not working earlier.
martin

Re: how to synchronize files from local to remote and delete local files in winscp

Anonymous wrote:

In the link that you shared, they have given example to synchronize remote to local and delete contents of remote. But i want the other way round - synchronize local to remote and delete local. Can you also plz test on your end and help me with the correct command?

Just use put -delete as the article suggests.
Guest

Re: how to synchronize files from local to remote and delete local files in winscp

martin wrote:

I want to delete the files from local directory once i have synchronized with remote directory.

See https://beta.winscp.net/eng/docs/faq_delete_synchronized_files


HI Martin,

In the link that you shared, they have given example to synchronize remote to local and delete contents of remote. But i want the other way round - synchronize local to remote and delete local. Can you also plz test on your end and help me with the correct command?
Guest

how to synchronize files from local to remote and delete local files in winscp

I want to delete the files from local directory once i have synchronized with remote directory.

Here is my script,
#Resources Can be Found here - https://beta.winscp.net/eng/docs/scripting
option batch abort
option confirm off
open scp://XXX:YYY@localhost -hostkey="ZZZ"
synchronize remote -delete [local directory] [remote directory]
exit

With the above script, files are getting deleted in remote directory.

If i use the below script, then files from remote is getting synchronized to my local.
synchronize local -delete [local directory] [remote directory]


If i switch the directory then i get an error,
synchronize local -delete [remote directory] [local directory]
tunilove

sync deleted my file

it seams i click somewhere by mistake and i got server file deleted how i get them back
Guest

Can you copy and paste your batch file in its complete form? i'm a little confused
tlw3

RESOLVED: Delete remote files after sync / copy

This is the solution I implemented:

In my batch file, I call WinSCP twice, invoking two different scripts.

The first script does my local sync:
synchronize local -filemask="*.*"

Then, in my batch file, I *move* those files to a permanent location, outside of the current hierarchy.

Now I invoke the second script which does a REMOTE synch with the delete option:
synchronize remote -delete -filemask="*.*"

Now I have all of my files with directory structure in tact, and the server has been properly cleaned.

My batch file looks something like this (simplified):

winscp.com /console /script="synch.scr" 
 
robocopy "tempdir" "finaldir" /MOVE /E
 
winscp.com /console /script="cleanup.scr"
maiza

I am pretty new to scripting in general, and I did not want to create another topic when I believe what I am trying to do is very similar.

I have attempted to write a script that will synchronize a local folder with a remote folder. After the synchronization, the files in the local folder should be deleted.

Here is what I wrote:
option confirm off
open ftpsession
synchronize remote -nopreservetime
synchronize remote -nopermissions
synchronize