Topic "Noobie to WinSCP - Delete after Sync help plz."

Author Message
munkdogg
[View user's profile]

Joined: 2009-09-25
Posts: 1
Location: Toronto
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;
Code:

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?
[/code]
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Pritesh Davda

Guest


"synchronize local -delete" command is not deleting files in remote folder Sad

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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
I have added topic on deleting files after synchronization to FAQ.
_________________
Martin Prikryl
JeffDallas

Guest


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.

Code:

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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
This is exactly what the FAQ I've linked in my post above yours answers.
So once again:
http://winscp.net/eng/docs/faq_delete_synchronized_files
_________________
Martin Prikryl
maiza
[View user's profile]

Joined: 2013-08-02
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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
You need to use a single synchronize command, like:
Code:
synchronize remote -nopreservetime -nopermissions -delte "C:\Users\Local\Directory" "/remote/directory"

See examples:
http://winscp.net/eng/docs/scriptcommand_synchronize
_________________
Martin Prikryl
tlw3
[View user's profile]

Joined: 2013-10-04
Posts: 2
Location: There is no true objective observer.
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"
Guest




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

Guest


it seams i click somewhere by mistake and i got server file deleted how i get them back
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
tunilove wrote:
it seams i click somewhere by mistake and i got server file deleted how i get them back

See https://winscp.net/eng/docs/faq_undelete
Advertisements

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License