I am currently using WinSCP to synchronize files between a remote path and a local path to a desktop computer. I would like to change this so that either of the following occurs:
- Move files from the remote path to the local path
- Copy files from the remote path to the local path, then delete only the files that were downloaded to the local path - on the remote server.
Is this possible?
Here is my current script, any assistance is very much appreciated.
@echo on
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
Based on https://winscp.net/eng/docs/library_example_delete_after_successful_download