Kaseya Community

Downloads using BITS

  • The following is a Proof-of-Concept script to create a BITS (Background Intelligent Transfer Service) job to download a file from a web server to a client. Useful if you find the need to distribute some fairly large files to people on the move...


    Script Name: BITS upload - POC
    Script Description:
    Script uploads a specific file to remote computer using BITS

    IF True
    THEN
    Write File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\BitsComplete.cmd
    Parameter 2 : VSASharedFiles\BitsComplete.cmd
    OS Type : 0
    Execute Shell Command
    Parameter 1 : bitsadmin.exe /create K-download
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : bitsadmin.exe /addfile K-download http://www.yoursite.c_o_m/downloads/file.zip #vAgentConfiguration.agentTempDir#\file.zip
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : bitsadmin /SetNotifyCmdLine K-download #vAgentConfiguration.agentTempDir#\BitsComplete.cmd NULL
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : bitsadmin /resume K-download
    Parameter 2 : 0
    OS Type : 0
    ELSE


    The content of the "bitscomplete.cmd" should be:

    @echo off
    @bitsadmin.exe /complete K-download >output.txt


    You can include anything else you want in there, or replace it completely with something else. However, no matter what you do, you need to execute the /complete part in order for BITS to mark the job as done and remove it from the list.

    See "bitsadmin /?" for a complete list of commands.

    Legacy Forum Name: Downloads using BITS,
    Legacy Posted By Username: Lmhansen
  • Thats pretty interesting. I knew BITS could be used for that but have never tried using it.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JonJohnston
  • JonJohnston
    Thats pretty interesting. I knew BITS could be used for that but have never tried using it.


    Once I started looking into it, I found that it was actually a lot easier than I initially thought it would be. Being able to use the commandline tool like this really simplified matters. Smile

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • Turns out, bitsadmin is not available by default on XP machines. It can be easily added though. Download the XP support pack and install it somewhere, then upload the bitsadmin.exe to your KServer.

    Add this script to the mix:

    Script Name: BITS Download step 1
    Script Description:

    IF Test File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\bitsadmin.exe
    Exists :
    THEN
    Execute Script
    Parameter 1 : BITS Download step 2 (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0
    ELSE
    Write File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\bitsadmin.exe
    Parameter 2 : VSASharedFiles\bitsadmin.exe
    OS Type : 0
    Execute Script
    Parameter 1 : BITS Download step 2 (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0


    Then change your download script to reference #vAgentConfiguration.agentTempDir#\bitsadmin.exe when executing the command.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen