Batch Tutorial – Downloading Script

Download a file from your server.

Here’s the second tutorial on the batch script. Here’s how you can automate downloading process from the server.

@echo off
set file_name=filename.pdf
set installer_path=\\192.168.0.xx\shares\directory_name\sample.pdf
set output_path=D:\Downloads
set log_path=D:\logs
echo Installing %software_name% ...
bitsadmin /transfer "DownloadJob" %installer_path% %output_path%
if %ERRORLEVEL% equ 0 (
  echo %file_name% downloaded successfully.
) else if %ERRORLEVEL% equ 5 (
  echo Access denied.
) else (
  echo An error occurred.
)

In this script, we’ve defined some variables to customize the installation:

  • file_name: The name of the file being installed.
  • installer_path: The network path to the file.
  • output_pat: the destination folder of the downloading file
  • log_path: The local path to the log file that will be generated during the installation.

The bitsadmin command is a built-in command in Windows that is used for managing Background Intelligent Transfer Service (BITS) jobs. In this script, the bitsadmin command is used to download the file specified in installer_path to the output_path. The /transfer option creates a new transfer job, “DownloadJob” specifies the name of the job, %installer_path% specifies the URL or file path to download from, and %output_path% specifies the file path to save the downloaded file to. Once the transfer is complete, the script checks the error level to determine whether the download was successful, and outputs an appropriate message.

Leave a Reply