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 offset file_name=filename.pdfset installer_path=\\192.168.0.xx\shares\directory_name\sample.pdfset output_path=D:\Downloadsset log_path=D:\logsecho 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 filelog_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.