Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem -- download utility by Vasil "npocmaka" Arnaudov
- setlocal
- :download
- if "%2" equ "" (
- call :help
- exit /b 5
- )
- if "%1" equ "" (
- call :help
- exit /b 6
- )
- set url=%~1
- set file=%~2
- rem ----
- if "%~3" NEQ "" (
- set /A timeout=%~3
- ) else (
- set timeout=5
- )
- bitsadmin /cancel download
- bitsadmin /create /download download
- call bitsadmin /addfile download "%url%" "%CD%\%file%"
- bitsadmin /resume download
- butsadmin /setproxysettings download AUTODETECT
- set /a attempts=0
- :repeat
- set /a attempts +=1
- if "%attempts%" EQU "10" (
- echo TIMED OUT
- endlocal
- exit /b 1
- )
- bitsadmin /info download /verbose | find "STATE: ERROR" && endlocal && bitsadmin /cancel download && echo SOME KIND OF ERROR && exit /b 2
- bitsadmin /info download /verbose | find "STATE: SUSPENDED" && endlocal && bitsadmin /cancel download &&echo FILE WAS NOT ADDED && exit /b 3
- bitsadmin /info download /verbose | find "STATE: TRANSIENT_ERROR" && endlocal && bitsadmin /cancel download &&echo TRANSIENT ERROR && exit /b 4
- bitsadmin /info download /verbose | find "STATE: TRANSFERRED" && goto :finishing
- sleep %timeout%
- goto :repeat
- :finishing
- bitsadmin /complete download
- echo download finished
- endlocal
- goto :eof
- :help
- echo %~n0 url file [timeout]
- echo.
- echo url - the source for download
- echo file - file name in local directory where the file will be stored
- echo timeout - number in seconds between each check if download is complete (attempts are 10)
- echo.
- goto :eof
Add Comment
Please, Sign In to add comment