Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

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)


Topic review


After downloading files using WinSCP – delete files that were downloaded from the remote server

I currently have a WinSCP script which uses synchronize. I would like to change it so that it downloads any files it sees from the remote server path, and then very importantly, it needs to delete the files from the remote server which it just downloaded. If a new file came in to the remote server path during the interval between the download and the delete command, then that new file must not be downloaded – only the files that were successfully downloaded must be deleted from the remote server. Is this possible and can it be scripted? Any assistance is much appreciated.

Here is the script:
@echo off
SET localdir=C:\Users\User1\Received
SET remotedir=\folder_1
SET logfile=C:\Users\Users1\Logs\Syncanddelete.log
SET prgwinscp=C:\Users\Users1\AppData\Local\Programs\WinSCP\
SET winscplogin="SyncandDelete"
SET winscpfile=%temp%\~tmpWinSCPFTPSyncT_%~N0.txt
IF EXIST "%winscpfile%" DEL /Q /F "%winscpfile%"
REM synchronize command:
SET ftpcmd=synchronize local -delete -mirror "%localdir%\"
>>"%logfile%" ECHO.
>>"%logfile%" ECHO ***************************  FTP OUT  ***************************
>>"%logfile%" ECHO Synchronizing files to %winscplogin% server  on %date% at %time%
>>"%winscpfile%" ECHO option batch on
>>"%winscpfile%" ECHO option confirm off
>>"%winscpfile%" ECHO option transfer binary
>>"%winscpfile%" ECHO open %winscplogin%
>>"%winscpfile%" ECHO cd "%remotedir%"
>>"%winscpfile%" ECHO %ftpcmd%
>>"%winscpfile%" ECHO close
>>"%winscpfile%" ECHO exit
>>"%logfile%" ECHO %winscpfile%                               
TYPE "%winscpfile%" >> %logfile%
>>"%logfile%" ECHO -------------------------------------------
"%prgwinscp%" /script="%winscpfile%" >>"%logfile%" 2>&1
>>"%logfile%" ECHO -------------------------------------------
IF EXIST "%winscpfile%" DEL /Q /F "%winscpfile%"
>>"%logfile%" ECHO Transmission complete on %date% at %time%
ping -n 2 -w 1000 > nul