BGet.cmd – Download Manager for BITS.

 

BITS, or Background Intelligent Transfer Service, is built-in Windows file-transfer technology introduced in Windows XP that has many features including bandwidth throttling and download resume allowing for successful download over unreliable network connections. Current version of BITS supports HTTP and HTTPS URLs as well as SMB (shared folders) as download sources. Windows components (such as Automatic Updates client) and Microsoft products (such as WSUS and SMS) use BITS to reliably download files from Internet and deliver them to client computers.

Now, I was always wondering, why no one (to my knowledge) yet created a general purpose download manager that uses BITS as underlying technology. While BITS has particular requirements for HTTP which can limit its use over Internet, it looks pretty sexy for large files transfer over LAN or WAN.

So I went ahead and created a proof-of-concept download manager in form of cmd script that uses bitsadmin.exe utility to communicate with BITS service. Over time, as this script matured, it became my primary tool for large files downloads (think ISO images or VHD virtual hard drives) from servers in corporate network.

Script has three modes: interactive, batch and notification. In interactive mode you have text-based menu tree to manage BITS downloads ("jobs" in terms of BITS) and can monitor downloads progress in real time. In batch mode you create a download job which starts in the background and then when download is finished, you get a notification CMD window with download statistics (that’s BGet in "notification mode"). And as I already said, you’ll need bitsadmin.exe utility to run this script. This utility ships with Windows Vista and is also available as part of Windows Support Tools for earlier versions of Windows.

Script syntax: 

C:\>bget /?

 

BGet v2.3, download manager for BITS service.

Downloads files using BITS service. Best suited for large files like ISO or VHD
images. Supports UNC and HTTP(S) sources, automatic resume and prioritization.
Runs in three modes: Interactive, Batch and "Notification Command".

 

1. Interactive mode can be used to manage existing jobs. To enter interactive
mode, run BGet without command line arguments.

 

2. In batch mode you can also create download jobs using following syntax.

   SYNTAX:
     BGet.cmd source target [-b] [-p:0|1]

        source - Source file URL. HTTP(S) and UNC are supported.
                 ========================================================
                 NOTE: URLs with symbols that are command delimiters like
                       "=" or ";" are not supported. Also are not supported URLs
                       that redirect to FTP servers.
                 ========================================================
        target - Full path to target file.
        -b     - Start BITS download job and exit. Download will continue
                 in background.
        -p     - Download prioriy. 1 is foreground, 0 - background. When
                 running at low priority, download will utilize only unused
                 network bandwidth. Default is foreground priority.

   EXAMPLES:
     BGet.cmd http://www.company.com/files/file.zip c:\download\file.zip -p:0
     BGet.cmd \\server\share\program.iso c:\download\program.iso -b

 

3. "Notification command" mode is used by download jobs. BGet configures job
   to invoke itself as notification command to inform user about job errors or
   that job has finished file transfer. Normally, you shouldn't run BGet in
   notification command mode manually.

   SYNTAX:
     BGet.cmd /notify Job_ID

        Job_ID - BITS job GUID.

   EXAMPLES:
    BGet.cmd /notify {F4FD319F-3174-452A-A43E-B3261944B2C0}

 

REQUIREMENTS:
   BITS service   - v1.5 for HTTP and HTTPS only.
                    v2.0 or later also supports SMB protocol (UNC paths).
   bitsadmin.exe  - Windows 2000/2003/XP - Part of Windows Support Tools.
                    Windows Vista - built-in.
REFERENCES:
   Bitsadmin.exe syntax:
   http://msdn2.microsoft.com/en-us/library/aa362813.aspx

 

To use this script, save the text under "Script listing" below to a text file, save the file with CMD extension and run it from command prompt window (for Vista users: elevation is not required). Enjoy.

 Script listing:

:: =============================================================================== :: Name: BGet.cmd :: :: Purpose: SMB/HTTP(S) Download manager. :: :: Syntax: BGet.cmd :: BGet.cmd source target [-b] [-p:0|1] [-?] :: BGet.cmd /notify Job_ID :: :: Version: 2.3 :: :: Requirements: BITS 1.5 for HTTP(S), BITS 2.0 or later for SMB, bitsadmin.exe :: :: Authors: Alexander Sukhovey (asuhovey@gmail.com) :: =============================================================================== @echo off setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION :: =============================================================================== :: =============================================================================== :: Variables and constants :: =============================================================================== :: =============================================================================== set sver=2.3 set job_prefix=[BGET] set pdownl=0 set ba=bitsadmin.exe set ban=bitsadmin.exe /RAWRETURN set wrap=31 set step=1000 set pause=2 set priority=FOREGROUND set background=0 set delim====================================================== set check_job_exist_err=& set bits_err=& set url_err=& set job_id=& :: =============================================================================== :: =============================================================================== :: Parse arguments :: =============================================================================== :: =============================================================================== set arg="%~1" set arg="%arg:"=%" :: '-debug' turns on echo for debugging purposes if %arg%=="-debug" echo on & shift /1 :: Finish the job when run as notify command line if %arg%=="/notify" set job_id=%2& goto NOTIFICATION_COMMAND :: Show script syntax if %arg%=="/?" (goto SYNTAX) else (if %arg%=="-?" goto SYNTAX) if %arg%=="/?more" goto SYNTAX_MORE :: If there are no other aguments , switch to interactive mode if %arg%=="" ( goto INTERACTIVE ) else ( goto BATCHMODE ) :: =============================================================================== :: =============================================================================== :: Main section :: =============================================================================== :: =============================================================================== :: ========================== :: Interactive mode :: ========================== :INTERACTIVE title BGet v%sver% Interactive Mode echo/ echo BGet v%sver% Interactive Mode. echo/ set main_menu_item=& set main_menu_item=& set return_answer=& set job_menu_item=& set exit_msg=What was that? Have some coffee and try again. :: Main Menu :MAIN_MENU call :CHECK_BITSADMIN if defined bits_err goto :EOF echo %delim% echo Main Menu echo %delim% echo/ set /a q=1 echo !q!. Add new download job & set /a q+=1 echo !q!. Monitor all jobs & set /a q+=1 echo !q!. Suspend all jobs [N/A] & set /a q+=1 echo !q!. Resume all jobs [N/A] & set /a q+=1 echo !q!. Cancel all jobs [N/A] & set /a q+=1 echo !q!. View help & set /a q1=q+1 echo/ echo Jobs list: echo/ call :ENUM_JOBS !q! if !n! EQU !q! ( echo No jobs created by BGet found. ) echo/ echo [Q]uit echo/ :MAIN_MENU_Q set main_menu_item= set q_msg=Select menu item [1-!q!] if !n! EQU !q1! set q_msg=%q_msg% or job [!n!] if !n! GTR !q1! set q_msg=%q_msg% or job [!q1!-!n!] set /p main_menu_item="%q_msg%: " echo/ :: Main Submenu 1. Add new job. if "%main_menu_item%"=="1" ( echo %delim% echo Add New Job Menu: echo %delim% echo/ echo To add a new job, use batch mode. View help for details. echo/ echo Press any key to return to Main Menu... pause>nul echo/ goto MAIN_MENU ) :: Main Submenu 2. Monitor all jobs with "bitsadmin /monitor" command. if "%main_menu_item%"=="2" ( call :CHECK_BITSADMIN if defined bits_err goto :EOF %ba% /monitor goto :EOF ) :: Main Submenu 3. Suspend all jobs. :: TODO if "%main_menu_item%"=="3" echo Not implemented & echo/ & goto MAIN_MENU_Q :: Main Submenu 4. Resume all jobs. :: TODO if "%main_menu_item%"=="4" echo Not implemented & echo/ & goto MAIN_MENU_Q :: Main Submenu 5. Cancel all jobs. :: TODO if "%main_menu_item%"=="5" echo Not implemented & echo/ & goto MAIN_MENU_Q :: Main Submenu 6. View help. if "%main_menu_item%"=="6" ( call :SYNTAX echo/ echo Press any key to return to menu... pause>nul echo/ goto MAIN_MENU ) :: Main Submenus !q1!-!n! (jobs) for /l %%S in (!q1!,1,!n!) do ( if !main_menu_item!==%%S ( call :GET_JOB %%S :JOB_MENU echo %delim% echo Job !main_menu_item! Menu echo %delim% echo 1. Show job details echo 2. Monitor job echo 3. Suspend job echo 4. Resume job echo 5. Cancel job echo/ echo [Q]uit echo [R]eturn to parent menu echo/ :JOB_MENU_Q set job_menu_item= set /p job_menu_item="Select menu item [1-5]: " echo/ if not defined job_menu_item goto :EOF set job_menu_item=!job_menu_item:"=! REM Job Submenu 1. List job details. if "!job_menu_item!"=="1" ( call :CHECK_JOB_EXIST !job_id! if defined check_job_exist_err goto MAIN_MENU call :JOB_DETAILS !job_id! echo/ goto JOB_MENU ) REM Job Submenu 2. Monitor job. if "!job_menu_item!"=="2" ( call :CHECK_JOB_EXIST !job_id! if defined check_job_exist_err goto MAIN_MENU! call :MONITOR !job_id! echo/ goto MAIN_MENU ) REM Job Submenu 3. Suspend job. if "!job_menu_item!"=="3" ( call :CHECK_JOB_EXIST !job_id! if defined check_job_exist_err goto MAIN_MENU %ban% /SUSPEND !job_id! echo/ goto JOB_MENU ) REM Job Submenu 4. Resume job. if "!job_menu_item!"=="4" ( call :CHECK_JOB_EXIST !job_id! if defined check_job_exist_err goto MAIN_MENU %ban% /RESUME !job_id! echo/ goto JOB_MENU ) REM Job Submenu 5. Cancel job. if "!job_menu_item!"=="5" ( call :CHECK_JOB_EXIST !job_id! if defined check_job_exist_err goto MAIN_MENU echo %delim% echo WARNING: YOU ARE ABOUT TO CANCEL JOB !main_menu_item!^! echo %delim% call :JOB_DETAILS !job_id! echo/ set /p cancel_answer="Are you sure you want to cancel this job [Y/N]? " if not defined cancel_answer goto :EOF set cancel_answer=!cancel_answer:"=! if not "!cancel_answer!"=="Y" if not "!cancel_answer!"=="y" ( echo/ echo Job was NOT canceled. echo/ goto JOB_MENU ) echo/ %ban% /CANCEL !job_id! echo/ goto MAIN_MENU ) REM Job Submenu R. Return to Main Menu. if "!job_menu_item!"=="R" goto MAIN_MENU if "!job_menu_item!"=="r" goto MAIN_MENU REM Job Submenu Q. Quit. if "!job_menu_item!"=="Q" goto :EOF if "!job_menu_item!"=="q" goto :EOF REM Job Menu default action goto JOB_MENU_Q ) ) :: Main Submenu Q. Quit. if "!main_menu_item!"=="Q" goto :EOF if "!main_menu_item!"=="q" goto :EOF :: Main Menu default action. echo %exit_msg% goto :EOF :: ========================== :: Batch mode :: ========================== :BATCHMODE title BGet v%sver% Batch Mode echo/ echo BGet v%sver% Batch Mode. echo/ :: Parse arguments set source="%~1" set source="%source:"=%" if %source%=="" goto SYNTAX call :CHECK_URL %source% if defined url_err goto :EOF shift /1 set target="%~1" set target="%target:"=%" :: TODO: Check target if %target%=="" goto SYNTAX shift /1 :P ARSE_LOOP set arg=%~1 :: DEBUG :: echo %arg% :: /DEBUG shift /1 if not defined arg goto CREATE_JOB set arg=%arg:"=% if "%arg%"=="/?" (goto SYNTAX) else (if "%arg%"=="-?" goto SYNTAX) if "%arg%"=="-b" (set background=1&goto PARSE_LOOP) if "%arg:~0,3%"=="-p:" ( set priority=%arg:~3,1% if not !priority!==0 ( if not !priority!==1 ( echo ERROR: Invalid valuse for /p switch: %arg:~3% goto SYNTAX ) else (set priority=FOREGROUND) ) else (set priority=LOW) goto PARSE_LOOP ) echo ERROR: Unknown argument: %arg% echo/ goto SYNTAX :CREATE_JOB echo Creating download job... echo/ :: Compose job name, replace illegal characters set job_name=%source:&=_% set job_name=%job_name:?=_% set job_name=%job_name:(=_% set job_name=%job_name:)=_% for %%I in (%job_name:"=%) do set replace=!replace!_%%I set job_name=%replace:~1% set job_name=%job_prefix%%job_name% :: Check if job already exists for /f %%I in ('%ban% /LIST ^| find /i "%job_name%"') do ( set job_id=%%I echo Warning: Job already exists^^^! echo/ set /p b_monitor_answer="Would you like to monitor running job [Y/N]? " if not "!b_monitor_answer!"=="y" if not "!b_monitor_answer!"=="Y" ( set /p b_cancel_answer="Would you like to cancel running job [Y/N]? " if not "!b_cancel_answer!"=="y" if not "!b_cancel_answer!"=="Y" goto :EOF %ban% /CANCEL !job_id! goto :EOF ) %ban% /RESUME !job_id!>nul call :MONITOR !job_id! goto :EOF ) :: Create download job, capture Job ID for later use. for /f "delims=" %%J in ('%ban% /CREATE /DOWNLOAD "%job_name%"') do ( set job_id=%%J ) :: Set notification command. %ban% /SETNOTIFYCMDLINE %job_id% "%comspec%" "/c %~fs0 /notify %job_id%">nul :: Add file to the job %ban% /ADDFILE %job_id% %source% %target% :: Set download priority %ban% /SETPRIORITY %job_id% %priority% echo/ set /p foo="Starting download job... "<nul %ban% /RESUME %job_id%>nul if "%background%"=="1" ( echo Done. goto :EOF ) else ( call :CHECK_JOB_EXIST !job_id! call :MONITOR !job_id! goto :EOF ) :: ========================== :: Notification command mode :: ========================== :NOTIFICATION_COMMAND :: Bitsadmin job status constants :: :: BG_JOB_STATE_QUEUED - Specifies that the job is in the queue and waiting :: to run. If a user logs off while their job is transferring, the job transitions :: to the queued state. set BG_JOB_STATE_QUEUED=QUEUED :: BG_JOB_STATE_CONNECTING - Specifies that BITS is trying to connect to the :: server. If the connection succeeds, the state of the job becomes :: BG_JOB_STATE_TRANSFERRING; otherwise, the state becomes BG_JOB_STATE_TRANSIENT_ERROR. set BG_JOB_STATE_CONNECTING = CONNECTING :: BG_JOB_STATE_TRANSFERRING - Specifies that BITS is transferring data for :: the job. set BG_JOB_STATE_TRANSFERRING=TRANSFERRING :: BG_JOB_STATE_SUSPENDED - Specifies that the job is suspended (paused). :: To suspend a job, call the IBackgroundCopyJob:: Suspend method. BITS automatically :: suspends a job when it is created. The job remains suspended until you call the :: IBackgroundCopyJob:: Resume, IBackgroundCopyJob:: Complete, or :: IBackgroundCopyJob:: Cancel method. set BG_JOB_STATE_SUSPENDED=SUSPENDED :: BG_JOB_STATE_ERROR - Specifies that a non-recoverable error occurred :: (the service is unable to transfer the file). If the error, such as an :: access-denied error, can be corrected, call the IBackgroundCopyJob:: Resume :: method after the error is fixed. However, if the error cannot be corrected, :: call the IBackgroundCopyJob:: Cancel method to cancel the job, or call the :: IBackgroundCopyJob:: Complete method to accept the portion of a download job that :: transferred successfully. set BG_JOB_STATE_ERROR=ERROR :: BG_JOB_STATE_TRANSIENT_ERROR - Specifies that a recoverable error occurred. BITS :: will retry jobs in the transient error state based on the retry interval you :: specify (see IBackgroundCopyJob:: SetMinimumRetryDelay). The state of the job :: changes to BG_JOB_STATE_ERROR if the job fails to make progress (see :: IBackgroundCopyJob:: SetNoProgressTimeout). BITS does not retry the job if a :: network disconnect or disk lock error occurred (for example, chkdsk is running) :: or the MaxInternetBandwidth Group Policy is zero. set BG_JOB_STATE_TRANSIENT_ERROR=TRANSIENT_ERROR :: BG_JOB_STATE_TRANSFERRED - Specifies that your job was successfully processed. :: You must call the IBackgroundCopyJob:: Complete method to acknowledge completion :: of the job and to make the files available to the client. set BG_JOB_STATE_TRANSFERRED=TRANSFERRED :: BG_JOB_STATE_ACKNOWLEDGED - Specifies that you called the :: IBackgroundCopyJob:: Complete method to acknowledge that your job completed :: successfully. set BG_JOB_STATE_ACKNOWLEDGED=ACKNOWLEDGED :: BG_JOB_STATE_CANCELLED - Specifies that you called the :: IBackgroundCopyJob:: Cancel method to cancel the job (remove the job from the :: transfer queue). set BG_JOB_STATE_CANCELLED=CANCELLED title BGet v%sver% Notification Command Mode echo/ echo BGet v%sver% Notification Command Mode. echo/ call :CHECK_BITSADMIN if defined bits_err ( echo Cannot complete the job. echo/ echo Press any key to exit... pause>nul goto :EOF ) for /f "tokens=1,2,3* delims= " %%I in ('%ban% /GETSTATE %job_id%') do ( if "%%I %%J %%K"=="Unable to find" ( echo ERROR: Cannot find Job with job ID %job_id%. It may be already completed. echo/ echo Press any key to exit... pause>nul goto :EOF ) else ( set BG_JOB_STATE=%%I ) ) if %BG_JOB_STATE%==%BG_JOB_STATE_TRANSIENT_ERROR% ( echo WARNING: Download job %job_id% is in permanent ERROR state. echo This may be due local problem with BITS service or with remote source server. echo You can cancel this job or resume it after you fix the problem. echo/ call :JOB_DETAILS %job_id% echo/ set /p notify_resume_answer="Resume the job [Y/N]? " echo/ if not defined notify_resume_answer goto :EOF set notify_resume_answer=!notify_resume_answer:"=! if not "!notify_resume_answer!"=="Y" (if not "!notify_resume_answer!"=="y" ( set /p notify_cancel_answer="Cancel the job [Y/N]? " echo/ if not defined notify_cancel_answer goto :EOF set notify_cancel_answer=!notify_cancel_answer:"=! if not "!notify_cancel_answer!"=="Y" (if not "!notify_cancel_answer!"=="y" ( echo Job was NOT cancelled. echo/ goto :EOF )) %ban% /CANCEL %job_id% echo/ echo Press any key to exit... pause>nul goto :EOF )) %ban% /RESUME %job_id% echo/ echo Press any key to exit... pause>nul goto :EOF ) if %BG_JOB_STATE%==%BG_JOB_STATE_TRANSFERRED% ( echo Download job %job_id% is ready to be completed. echo/ call :JOB_DETAILS %job_id% echo/ set /p foo="Completing the job... "<nul for /f "delims=" %%I in ('%ban% /COMPLETE %job_id%') do (echo %%I) echo/ echo Press any key to exit... pause>nul ) goto :EOF :: =============================================================================== :: =============================================================================== :: Subroutines :: =============================================================================== :: =============================================================================== :: Monitor download progress :MONITOR set mon_count=0 echo/ echo %delim% echo Monitoring Job %1 for /f "delims=" %%I in ('%ban% /GETDISPLAYNAME %1') do (echo %%I) echo %delim% echo Stop monitoring with ^^C. This will not affect job echo progress. echo %delim% echo/ call :WSHTIME set start_time=%wsh_time% for /f %%Y in ('%ban% /GETBYTESTRANSFERRED %1') do set start_bytes=%%Y :MONITOR_LOOP for /f "tokens= 2,3,7,9 delims= " %%K in ('%ban% /NOWRAP /INFO %1') do ( set jname=%%K set state=%%L set downl=%%M set total=%%N ) if !mon_count! GEQ %wrap% ( set /a mon_count=0 call :WSHTIME set end_time=!wsh_time! call :WSHCALC ^^^^^(!downl!-!start_bytes!^^^^^)/^^^^^(^^^^^(!end_time!-!start_time!^^^^^)*1024^^^^^) 2 set speed_kbs=!result! call :WSHCALC 100*!downl!/!total! 2 set result=0!result! set result=!result:~-5! echo [!result!%%] !speed_kbs! KB/s set start_bytes=!downl! set start_time=!end_time! ) else ( rem Commented to save some CPU cycles. rem call :WSHCALC !downl!-!pdownl! 0 rem if !result! GEQ %step% ( if not "!downl!"=="!pdownl!" ( set pdownl=!downl! set /p foo=.<nul set /a mon_count+=1 ) ) ping -n %pause% 127.0.0.1 >nul 2>&1 if not !downl! EQU !total! (goto :MONITOR_LOOP) if !mon_count! GTR 0 if !mon_count! LSS %wrap% ( set /a mon_count+=1 for /l %%X in (!mon_count!,1,%wrap%) do set /p foo="."<nul for /f "delims=" %%I in ('%ban% /GETCREATIONTIME %1') do (set job_start_time=%%I) for /f "delims=" %%I in ('%ban% /GETCOMPLETIONTIME %1') do (set job_end_time=%%I) for /f "delims=" %%I in ('%ban% /GETBYTESTOTAL %1') do (set job_bytes_total=%%I) call :WSHTIME "!job_start_time!" set s_job_start_time=!wsh_time! call :WSHTIME "!job_end_time!" set s_job_end_time=!wsh_time! call :WSHCALC !job_bytes_total!/1048576 2 set job_mbytes_total=!result! call :WSHCALC !job_bytes_total!/^^^^^(^^^^^(!s_job_end_time!-!s_job_start_time!^^^^^)*1024^^^^^) 2 echo [100%%] echo/ echo Job statistics: echo Start time.......!job_start_time! echo End time.........!job_end_time! echo Total size.......!job_mbytes_total! MB echo Average speed:...!result! KB/sec ) echo/ echo/ goto :EOF :: Perform simple math using VBScript. :WSHCALC set wshcalc="%temp%\wshcalc%sver%.vbs" if not exist %wshcalc% echo On Error Resume Next:WScript.Echo FormatNumber(Eval(WScript.Arguments(0)),WScript.Arguments(1),-1,-1,0)>%wshcalc% for /f "tokens=*" %%A in ('cscript /nologo %wshcalc% %1 %2') do set result=%%A :: del %wshcalc%>nul 2>&1 goto :EOF :: Perform date/time math using VBScript. :WSHTIME set wshtime_script="%temp%\wshtime%sver%.vbs" if not exist %wshtime_script% echo On Error Resume Next:If WScript.Arguments.Count^>0 Then sTime=WScript.Arguments(0) Else sTime=Now End If:WScript.Echo DateDiff("s","1/1/1970 12:00:00 AM",sTime)>%wshtime_script% for /f "tokens=*" %%A in ('cscript /nologo %wshtime_script% %1') do set wsh_time=%%A goto :EOF :: Check if bitsadmin.exe is available :CHECK_BITSADMIN for %%I in (bitsadmin.exe) do ( if "%%~$PATH:I"=="" ( if not exist %%I ( echo ERROR: Cannot find required file '%%~I' echo/ set bits_err=1 ) else ( (set bits_err=) set ba="%%I" set ban="%%I" /RAWRETURN ) ) else ( (set bits_err=) set ba="%%~$PATH:I" set ban="%%~$PATH:I" /RAWRETURN ) ) goto :EOF :: Check if source is supported URL :CHECK_URL set url=%1 set url_err= if not "%url:~1,7%"=="http://" ( if not "%url:~1,8%"=="https://" ( if not "%url:~1,2%"=="\\" ( echo ERROR: Invalid source URL '%url%' echo Only UNC paths and HTTP^(S^) links are supported. set url_err=1 ) ) ) goto :EOF :CHECK_JOB_EXIST for /f "tokens=1,2,3* delims= " %%I in ('%ban% /GETSTATE %1') do ( if "%%I %%J %%K"=="Unable to find" ( echo ERROR: Cannot find Job with job ID %1. It may be already completed. echo/ set check_job_exist_err=1 ) else (set check_job_exist_err=) ) goto :EOF :: List job details :JOB_DETAILS echo Job details: echo/ echo Job ID: !job_id! for /f "delims=" %%I in ('%ban% /GETDISPLAYNAME %1') do (echo Display name: %%I) for /f "delims=" %%I in ('%ban% /GETDESCRIPTION %1') do (echo Description: %%I) for /f "delims=" %%I in ('%ban% /GETSTATE %1') do (echo Status: %%I) for /f "delims=" %%I in ('%ban% /GETOWNER %1') do (echo Owner: %%I) for /f "delims=" %%I in ('%ban% /GETPRIORITY %1') do (echo Priority: %%I) for /f "delims=" %%I in ('%ban% /GETMINRETRYDELAY %1') do (echo Retry delay: %%I seconds) for /f "delims=" %%I in ('%ban% /GETNOPROGRESSTIMEOUT %1') do (echo Timeout: %%I seconds) for /f "delims=" %%I in ('%ban% /GETFILESTOTAL %1') do (echo Files Total: %%I) set /p foo="Files list: "<nul for /f "tokens=5*" %%I in ('%ban% /LISTFILES %1') do (echo %%I %%J) echo/ echo Job statistics: echo/ for /f "delims=" %%I in ('%ban% /GETCREATIONTIME %1') do (echo Created: %%I) for /f "delims=" %%I in ('%ban% /GETCOMPLETIONTIME %1') do (echo Completed: %%I) for /f "delims=" %%I in ('%ban% /GETFILESTOTAL %1') do (set files_total=%%I) for /f "delims=" %%I in ('%ban% /GETBYTESTOTAL %1') do (set bytes_total=%%I) for /f "delims=" %%I in ('%ban% /GETFILESTRANSFERRED %1') do (echo Files Transferred %%I/!files_total!) for /f "delims=" %%I in ('%ban% /GETBYTESTRANSFERRED %1') do ( call :WSHCALC 100*%%I/!bytes_total! 2 echo Bytes Transferred: %%I/!bytes_total! ^(!result!%%^) ) for /f "delims=" %%I in ('%ban% /GETERRORCOUNT %1') do (echo Error count: %%I & set job_errcount=%%I) if %job_errcount% GTR 0 ( for /f "delims=" %%I in ('%ban% /GETERROR %1') do (echo %%I)) :: for /f "delims=" %%I in ('%ban% /GETMODIFICATIONTIME %1') do (echo Modified: %%I) :: for /f "delims=" %%I in ('%ban% /GETNOTIFYFLAGS %1') do (echo Notify flags: %%I) :: for /f "delims=" %%I in ('%ban% /GETNOTIFYINTERFACE %1') do (echo Notify interface: %%I) goto :EOF :: Enumerate jobs, save jobs IDs to environment variables :ENUM_JOBS set /a n=%1 for /f "tokens=1,2,3" %%I in ('%ban% /list') do ( set item=%%J if "!item:~0,1!"=="'" if "!item:~-1!"=="'" ( set item=!item:~0,-1! set item=!item:~1! ) if "!item:~0,6!"=="%job_prefix%" ( set /a n+=1 echo !n!. %%J %%K set BGET_JOB_!n!=%%I ) ) goto :EOF :: Retrieve jod ID from environment variables :GET_JOB for /f "tokens=2 delims==" %%O in ('set BGET_JOB_%1 ^| find "BGET_JOB_%1="') do (set job_id=%%O&goto :EOF) goto :EOF :: Output script syntax :SYNTAX "%~f0" /?more | more goto :EOF :SYNTAX_MORE echo/ echo BGet v%sver%, download manager for BITS service. echo/ echo Downloads files using BITS service. Best suited for large files like ISO or VHD echo images. Supports UNC and HTTP^(S^) sources, automatic resume and prioritization. echo Runs in three modes: Interactive, Batch and "Notification Command". echo/ echo 1. Interactive mode can be used to manage existing jobs. To enter interactive echo mode, run BGet without command line arguments. echo/ echo 2. In batch mode you can also create download jobs using following syntax. echo/ echo SYNTAX: echo BGet.cmd source target [-b] [-p:0^|1] echo/ echo source - Source file URL. HTTP(S) and UNC are supported. echo ======================================================== echo NOTE: URLs with symbols that are command delimiters like echo "=" or ";" are not supported. Also are not supported URLs echo that redirect to FTP servers. echo ======================================================== echo target - Full path to target file. echo -b - Start BITS download job and exit. Download will continue echo in background. echo -p - Download prioriy. 1 is foreground, 0 - background. When echo running at low priority, download will utilize only unused echo network bandwidth. Default is foreground priority. echo/ echo EXAMPLES: echo BGet.cmd http://www.company.com/files/file.zip c:\download\file.zip -p:0 echo BGet.cmd \\server\share\program.iso c:\download\program.iso -b echo/ echo 3. "Notification command" mode is used by download jobs. BGet configures job echo to invoke itself as notification command to inform user about job errors or echo that job has finished file transfer. Normally, you shouldn't run BGet in echo notification command mode manually. echo/ echo SYNTAX: echo BGet.cmd /notify Job_ID echo/ echo Job_ID - BITS job GUID. echo/ echo EXAMPLES: echo BGet.cmd /notify {F4FD319F-3174-452A-A43E-B3261944B2C0} echo/ echo/ echo REQUIREMENTS: echo BITS service - v1.5 for HTTP and HTTPS only. echo v2.0 or later also supports SMB protocol (UNC paths). echo bitsadmin.exe - Windows 2000/2003/XP - Part of Windows Support Tools. echo Windows Vista - built-in. echo REFERENCES: echo Bitsadmin.exe syntax: echo http://msdn2.microsoft.com/en-us/library/aa362813.aspx echo/ goto :EOF :: =============================================================================== :: End of script :: ===============================================================================

Запись опубликована в рубрике Uncategorized. Добавьте в закладки постоянную ссылку.

5 комментариев на «BGet.cmd – Download Manager for BITS.»

  1. Alexander говорит:

    thanks!

  2. Nash говорит:

    HI!im trying to run this from a bat script, however after running this command once, It seems to exit my bat calling script after the first file will transfer.In my script I have multiple lines in the format:bget (link) (save destination) -bif i try and put \’call\’ before it, it seems to skip through the entire thing and not download anything.ive rem\’ed a few pause>nullines so that it doesnt require input to run but it appears im clearly not an experienced bat scripter to get this.can you shed some light on this for me?thanks for the script!

  3. Уведомление: Копирование больших файлов при помощи PowerShell (с использованием службы BITS) - ShS's Blog

  4. Frances Chestand говорит:

    Do you mind if I quote a few of your posts as long as I provide credit and sources back to your webpage? My blog is in the exact same area of interest as yours and my visitors would really benefit from a lot of the information you present here. Please let me know if this okay with you. Cheers!

Добавить комментарий

Fill in your details below or click an icon to log in:

Логотип WordPress.com

You are commenting using your WordPress.com account. Log Out / Изменить )

Фотография Twitter

You are commenting using your Twitter account. Log Out / Изменить )

Фотография Facebook

You are commenting using your Facebook account. Log Out / Изменить )

Connecting to %s