diff --git a/software/.gitignore b/software/.gitignore index 0795aa1..557c8b9 100644 --- a/software/.gitignore +++ b/software/.gitignore @@ -15,4 +15,6 @@ *.part *.key *.ttf +remotesize +localsize diff --git a/software/download-from-ftp.cmd b/software/download-from-ftp.cmd index 9168eda..8e26c8c 100644 --- a/software/download-from-ftp.cmd +++ b/software/download-from-ftp.cmd @@ -1,5 +1,7 @@ @echo off set FTPSETTINGS=..\custom\ftpsettings.cmd +set LOCALSIZE=localsize +set REMOTESIZE=remotesize rem =================== rem CONFIGFILE CHECK @@ -43,6 +45,10 @@ echo FTP_PASS=xxxxxx echo ++++++++++++++++++ echo. +rem cleanup ... +del /F /Q remotesize 2>nul +del /F /Q localsize 2>nul + echo disabling Windows defender for PATH [ %USERPROFILE% ] ... powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %USERPROFILE% echo. @@ -55,24 +61,13 @@ rem ################################### FOR /F "tokens=1,2 delims=, " %%E in (%LISTFILE%) do ( - IF NOT EXIST %%F ( + rem get local file size ... + FORFILES /M %%F /C "cmd /C echo Content-Length: @fsize >%LOCALSIZE%" - rem get it with curl ... - echo. - echo getting: [ %%F ] - curl -u %FTP_USER%:%FTP_PASS% -L ftp://%FTP_SERVER%/%FTP_PATH%/%%F --output %%F + rem get remote file size ... + curl -u %FTP_USER%:%FTP_PASS% -s -I ftp://%FTP_SERVER%/%FTP_PATH%/%%F | findstr Content-Length >%REMOTESIZE% - rem success ? - if NOT EXIST %%F ( - echo ERROR: couldn't get %%F! - ) ELSE ( - rem check size (it SHOULD NOT be 0!) - FORFILES /M %%F /C "cmd /C if @fsize EQU 0 echo ERROR: file @relpath is zero size!" - ) - - ) ELSE ( - FORFILES /M %%F /C "cmd /C if @fsize NEQ 0 echo OK: file @relpath is [ @fsize ] bytes" - ) + call :compare %%F ) @@ -81,10 +76,42 @@ rem END rem ===== GOTO END + +:compare + rem COMPARE both ... + fc /W %LOCALSIZE% %REMOTESIZE% + + if %ERRORLEVEL% GTR 0 ( + + rem get it with curl ... + echo. + echo getting: [ %1 ] + curl -u %FTP_USER%:%FTP_PASS% -L ftp://%FTP_SERVER%/%FTP_PATH%/%1 --output %1 + + rem success ? + if NOT EXIST %1 ( + echo ERROR: couldn't get %1! + ) else ( + rem check size (it SHOULD NOT be 0!) + FORFILES /M %1 /C "cmd /C if @fsize EQU 0 echo ERROR: file @relpath is zero size!" + ) + + ) else ( + echo OK. File [ %1 ] is same size. + ) + +goto :eof + + :USAGE echo "usage: %0 " echo LISTFILE = basic, browser, optional or other echo. :END +echo. +echo cleanup ... +del /F /Q remotesize 2>nul +del /F /Q localsize 2>nul +echo.