I include my coding and testing coding.
@echo off
rem Settings.
rem Server Login
set session=AutoFTP1
rem Folder Settings.
set ftp_path=/homedir/homedata/
rem set monitor_path=C:\tempdata\
FOR /F "usebackq tokens=2 delims==" %%a IN ("%winscp_path%pathConfig.txt") do (
set monitor_path=%%a
)
rem Path to winscp.
set winscp_path=C:\Program Files (x86)\WinSCP\
rem Log File 1 or 0.
set logfile=1
rem set filename=%date:~0,2%%date:~3,2%%date:~6,6%_FTPLogs
set filename=SFTPLogs
FOR /F "usebackq tokens=1-5 delims=," %%a IN ("%winscp_path%machineFileType.txt") do (
set mfileType=%%e
)
echo %errorlevel%
If exist script.tmp del script.tmp
rem echo > %filename%.txt
echo option batch on >> script.tmp
echo option confirm off >> script.tmp
echo open %session% >> script.tmp
echo option transfer binary >> script.tmp
echo dir "%ftp_path%%mfileType%" >nul 2>nul >> script.tmp
If errorlevel 1 (echo No Error) else (echo Error Found!)
rem echo mkdir "%computername%" >> script.tmp
rem echo mkdir "%ftp_path%%mfileType%/%computername%/" >> script.tmp
rem echo keepuptodate %monitor_path% "%ftp_path%%mfileType%/%computername%/" >> script.tmp
echo exit >> script.tmp
IF "%logfile%"=="1" (set filelog=/xmllog=%filename%_!M!D!Y.xml)
"%winnscp_path%WinSCP.com" /script=script.tmp %filelog% /xmlgroups
I want to write a batch scritp if Remote FTP Folder Exist, just keepuptodate, else folder does not exist mkdir first, otherwise in xml logs always shown Error Creating folder although my keepuptodate still running.
No matter errorlevel is 0 or 1, it always print Error Found!.