From 7481ca855bd8d5d39cdc453c4d49e5e5d892472d Mon Sep 17 00:00:00 2001 From: "Michael H.G. Schmidt" Date: Mon, 8 Mar 2021 23:13:58 +0100 Subject: [PATCH] added download from ftp script --- software/download-from-ftp.cmd | 84 ++++++++++++++++++++++++++++++++++ software/download-software.cmd | 1 + software/upload-to-ftp.cmd | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 software/download-from-ftp.cmd diff --git a/software/download-from-ftp.cmd b/software/download-from-ftp.cmd new file mode 100644 index 0000000..d9e7a5d --- /dev/null +++ b/software/download-from-ftp.cmd @@ -0,0 +1,84 @@ +@echo off + +rem =================== +rem CONFIGFILE CHECK +rem =================== + +if NOT EXIST ftpsettings.cmd ( + echo. + echo ERROR: ftpsettings.cmd NOT FOUND + echo. + echo --- please create with following content --- + 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 ... +call ftpsettings.cmd +echo ++++++++++++++++++ +echo FTP_SERVER=%FTP_SERVER% +echo FTP_PATH=%FTP_PATH% +echo FTP_USER=%FTP_USER% +echo FTP_PASS=xxxxxx +echo ++++++++++++++++++ +echo. + +echo using list [ %LISTFILE% ] ... + +rem ################################### +rem MAIN loop ( DOWNLOAD from ftp ) ... +rem ################################### + +FOR /F "tokens=1,2 delims=, " %%E in (%LISTFILE%) do ( + + IF NOT EXIST %%F ( + + 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 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" + ) + +) + +rem ===== +rem END +rem ===== +GOTO END + +:USAGE +echo "usage: %0 " +echo LISTFILE = basic, browser, optional or other +echo. + +:END diff --git a/software/download-software.cmd b/software/download-software.cmd index 79906a0..41d1d4c 100644 --- a/software/download-software.cmd +++ b/software/download-software.cmd @@ -32,6 +32,7 @@ FOR /F "tokens=1,2 delims=, " %%E in (%LISTFILE%) do ( IF NOT EXIST %%F ( rem get it with curl ... + echo. echo getting: %%F [ %%E ] curl --connect-timeout 5 --fail-early -L %%E --output %%F diff --git a/software/upload-to-ftp.cmd b/software/upload-to-ftp.cmd index 85e82a5..0c35311 100644 --- a/software/upload-to-ftp.cmd +++ b/software/upload-to-ftp.cmd @@ -45,7 +45,7 @@ echo. echo using list [ %LISTFILE% ] ... rem ################################### -rem MAIN loop ( UPLOAD software ) ... +rem MAIN loop ( UPLOAD top ftp ) ... rem ################################### FOR /F "tokens=1,2 delims=, " %%E in (%LISTFILE%) do (