Noobie to WinSCP - Delete after Sync help plz.

Advertisement

munkdogg
Joined:
Posts:
1
Location:
Toronto

Noobie to WinSCP - Delete after Sync help plz.

Thus far my experience with WinSCP is about 3 days.

Thanks in large part to the examples & content on this site (which are superb), I have composed the following script to synchronize the contents of a remote dir with the local dir;
option batch on
option confirm off
open username:password@sftp.site.com
cd /remotedir
option transfer binary
synchronize local -delete
synchronize local c:\localdir /remotedir
close
exit
It would seem the files are being synchronize w/o any issue, but the contents of the remote dir are not being deleted.

Is there something I have missed in using this condition in my script?

Reply with quote

Advertisement

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

Re: Noobie to WinSCP - Delete after Sync help plz.

I guess you expect your script to delete whole remote directory after synchronizing. It does not do that. The -delete switch tells it to delete whatever files are not present in the opposite directory.
If you want to delete the remote directory, do it explicitly with rmdir command.

Reply with quote

Pritesh Davda
Guest

Re: Noobie to WinSCP - Delete after Sync help plz.

synchronize local -delete command is not deleting files in remote folder :(

Keepuptodate is quite good solution but it runs as a service and I prefer to run job once or twice a day.

Any advise on why synchronize local -delete command is not working?

Reply with quote

martin
Site Admin
martin avatar

Re: Noobie to WinSCP - Delete after Sync help plz.

Pritesh Davda wrote:

Any advise on why synchronize local -delete command is not working?
The command by definition removes file in local directory only. Please read documentation. If that does not help, come back.

Reply with quote

Advertisement

JeffDallas
Guest

Still having trouble with deleting source files after transf

I am trying to pull files from a remote location to a local location and delete the sources files on success.

We are running this at a .bat.
winscp.exe /console /command 
"open FTPLogin" 
"synchronize local -delete -filemask="*.zip" "
"\\target\location\"
" /sourceLocation" 
"close" 
"exit"

The files transfer just fine, but the source files remain. I think I'm missing one little thing but after digging around the forums I haven't been able to get it to work.

Thanks

Reply with quote

maiza
Joined:
Posts:
1
Location:
USA

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 remote "C:\Users\Local\Directory" "/remote/directory"
synchronize remote -delete
exit
It is transferring the text files, but it is still giving me a permissions/preserve timestamp error for most of the runs I do. Also, none of the files in the local directory are being deleted afterwards.

I apologize for my inexperience. Any help would be appreciated.
It synchronizes, but generates a fi

Reply with quote

Advertisement

tlw3
Joined:
Posts:
2
Location:
There is no true objective observer.

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"

Reply with quote

Advertisement

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://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]

Reply with quote

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://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?

Reply with quote

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

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.

Reply with quote

Advertisement

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.

Reply with quote

vladimir_andrei
Guest

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

Reply with quote

vladimir_andrei
Guest

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!

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum