w10install/software/download-from-ftp.cmd

113 lines
2.4 KiB
Batchfile
Raw Permalink Normal View History

2021-03-08 23:13:58 +01:00
@echo off
2024-02-23 14:03:56 +01:00
set FTPSETTINGS=..\custom\ftpsettings.cmd
2024-12-02 03:00:43 +01:00
set LOCALSIZE=localsize
set REMOTESIZE=remotesize
2021-03-08 23:13:58 +01:00
rem ===================
rem CONFIGFILE CHECK
rem ===================
2021-03-13 23:32:05 +01:00
if NOT EXIST %FTPSETTINGS% (
2021-03-08 23:13:58 +01:00
echo.
2021-03-13 23:32:05 +01:00
echo ERROR: %FTPSETTINGS% NOT FOUND
2021-03-08 23:13:58 +01:00
echo.
2021-03-13 00:30:15 +01:00
echo --- please create it as follows ---
2021-03-08 23:13:58 +01:00
echo set FTP_SERVER=example.com
echo set FTP_PATH=/path/to/directory
echo set FTP_USER=myuser
echo set FTP_PASS=mypass
exit /b
)
rem ===================
rem COMMANDLINE CHECKS
rem ===================
IF %1.==. GOTO USAGE
rem removing extension ...
set LISTFILE=%~n1
rem adding extension again ...
set LISTFILE=%LISTFILE%.csv
IF NOT EXIST %LISTFILE% (
echo ERROR: %LISTFILE% not found!
exit /b
)
echo.
echo loading settings ...
2021-03-13 23:32:05 +01:00
call %FTPSETTINGS%
2021-03-08 23:13:58 +01:00
echo ++++++++++++++++++
echo FTP_SERVER=%FTP_SERVER%
echo FTP_PATH=%FTP_PATH%
echo FTP_USER=%FTP_USER%
echo FTP_PASS=xxxxxx
echo ++++++++++++++++++
echo.
2024-11-19 13:17:59 +01:00
echo disabling Windows defender for PATH [ %USERPROFILE% ] ...
powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %USERPROFILE%
echo.
2021-03-08 23:13:58 +01:00
echo using list [ %LISTFILE% ] ...
rem ###################################
rem MAIN loop ( DOWNLOAD from ftp ) ...
rem ###################################
FOR /F "tokens=1,2 delims=, " %%E in (%LISTFILE%) do (
2024-12-02 10:12:19 +01:00
call :cleanup
2024-12-02 03:00:43 +01:00
rem get local file size ...
FORFILES /M %%F /C "cmd /C echo Content-Length: @fsize >%LOCALSIZE%"
2024-12-02 10:12:19 +01:00
2024-12-02 03:00:43 +01:00
rem get remote file size ...
curl -u %FTP_USER%:%FTP_PASS% -s -I ftp://%FTP_SERVER%/%FTP_PATH%/%%F | findstr Content-Length >%REMOTESIZE%
call :compare %%F
)
2024-12-02 10:12:19 +01:00
GOTO :cleanup
GOTO :END
2024-12-02 03:00:43 +01:00
:compare
2024-12-02 10:12:19 +01:00
rem COMPARE both ...
fc /W %LOCALSIZE% %REMOTESIZE% 1>nul 2>nul
2021-03-08 23:13:58 +01:00
2024-12-02 10:12:19 +01:00
if %ERRORLEVEL% GTR 0 (
2021-03-08 23:13:58 +01:00
2024-12-02 10:12:19 +01:00
rem get it with curl ...
echo.
echo getting: [ %1 ]
curl -u %FTP_USER%:%FTP_PASS% -L ftp://%FTP_SERVER%/%FTP_PATH%/%1 --output %1
2021-03-08 23:13:58 +01:00
2024-12-02 10:12:19 +01:00
rem success ?
if NOT EXIST %1 (
echo ERROR: couldn't get %1!
2024-12-02 03:00:43 +01:00
) else (
2024-12-02 10:12:19 +01:00
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!"
)
2021-03-08 23:13:58 +01:00
2024-12-02 10:12:19 +01:00
) else (
echo OK. File [ %1 ] is same size.
)
2024-12-02 03:00:43 +01:00
goto :eof
2021-03-08 23:13:58 +01:00
2024-12-02 10:12:19 +01:00
:cleanup
del /F /Q remotesize 2>nul
del /F /Q localsize 2>nul
goto :eof
2021-03-08 23:13:58 +01:00
:USAGE
echo "usage: %0 <LISTFILE>"
echo LISTFILE = basic, browser, optional or other
echo.
2024-12-02 10:12:19 +01:00
goto :END
2021-03-08 23:13:58 +01:00
2024-12-02 10:12:19 +01:00
rem =====
rem END
rem =====
2021-03-08 23:13:58 +01:00
:END
2023-01-01 15:16:29 +01:00