@ECHO OFF
REM VARIABLES
set COUNT=1
set VEHICLE_MAX=32
set dir_time=%DATE%

echo Start of sftp backup script %dir_time%
rem create the date info
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( 
	Set Month=%%B
	Set Day=%%A
	Set Year=%%C
)
set DIR_DATE=%Year%.%Month%.%Day%
REM mkdir %DIR_DATE%
@echo DIR = %DIR_DATE%
REM cd %DIR_DATE%
set user=ftp
set password=sftp

:Loop
echo VEHICLE %COUNT%

REM set up the ip address
set IP=10.72.10.%COUNT%

ping -n 1 %IP%>nul
if errorlevel 1 goto:skipftp

REM create the sftp commands file
> sftp.txt ECHO open sftp://%user%:%password%@%IP%
>> sftp.txt ECHO option batch abort
>> sftp.txt ECHO option confirm off
>> sftp.txt ECHO option transfer binary
>> sftp.txt ECHO option batch continue
>> sftp.txt ECHO cd /asc/config
>> sftp.txt ECHO get vehicle.conf AB%COUNT%.vehicle.conf
>> sftp.txt ECHO close
>> sftp.txt ECHO exit

REM do the sftp 
WinSCP.com /script=sftp.txt

:skipftp
REM increment the counter
set /A COUNT=COUNT+1
IF "%COUNT%" == "%VEHICLE_MAX%" GOTO End
goto Loop

:End

copy /y *.conf D:\Code_Update\asc\config\
REM del *.conf

rem echo "Run the web part in order to insert into the DB" 
rem "wget" -O crap http://ptsweb/Brisbane/Software/VehicleConfig.aspx
rem echo "end of script"



