@echo off
set FTPSETTINGS=..\company\ftpsettings.cmd
set APPSFOLDER=storeapps

rem ===================
rem CONFIGFILE CHECK
rem ===================

if NOT EXIST %FTPSETTINGS% (
  echo.
  echo ERROR: %FTPSETTINGS% NOT FOUND
  echo.
  echo --- please create it as follows ---
  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
)

echo.
echo loading settings ...
call %FTPSETTINGS%
echo ++++++++++++++++++
echo FTP_SERVER=%FTP_SERVER%
echo FTP_PATH=%FTP_PATH%
echo FTP_USER=%FTP_USER%
echo FTP_PASS=xxxxxx
echo ++++++++++++++++++
echo.

rem #####################################
rem MAIN loop ( UPLOAD apps to ftp ) ...
rem #####################################

mkdir %APPSFOLDER% 2>nul
IF EXIST %APPSFOLDER% (
  rem get all apps with wGET ...
  cd %APPSFOLDER%
  wget -nv -c -nd -N --user=%FTP_USER% --password=%FTP_PASS% ^
    ftp://%FTP_SERVER%/%FTP_PATH%/%APPSFOLDER%/*.*
) else (
  echo WARNING: [ %APPSFOLDER% ] does not exist, cannot download ...
)
cd ..

