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:
Here is the script:
@echo off cls :SetFileLogVariables SET localdir=C:\Users\User1\Received SET remotedir=\folder_1 SET logfile=C:\Users\Users1\Logs\Syncanddelete.log :SetPrgVariables SET prgwinscp=C:\Users\Users1\AppData\Local\Programs\WinSCP\WinSCP.com SET winscplogin="SyncandDelete" SET winscpfile=%temp%\~tmpWinSCPFTPSyncT_%~N0.txt IF EXIST "%winscpfile%" DEL /Q /F "%winscpfile%" :SetWinSCPSyncCommand REM synchronize command: https://winscp.net/eng/docs/scriptcommand_synchronize SET ftpcmd=synchronize local -delete -mirror "%localdir%\" :ftpout >>"%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 127.0.0.1 > nul