BASH
Download Multiple Files from a List of URLs
Efficiently download multiple files listed in a text file using a simple bash script, perfect for bulk asset retrieval or data synchronization tasks.
#!/bin/bash
URL_LIST_FILE="urls.txt"
DESTINATION_DIR="/path/to/downloads"
mkdir -p "$DESTINATION_DIR"
if [ ! -f "$URL_LIST_FILE" ]; then
echo "Error: URL list file '$URL_LIST_FILE' not found." >&2
exit 1
fi
while IFS= read -r url
do
if [ -n "$url" ]; then # Skip empty lines
echo "Downloading: $url"
wget -P "$DESTINATION_DIR" "$url"
if [ $? -ne 0 ]; then
echo "Warning: Failed to download $url" >&2
fi
fi
done < "$URL_LIST_FILE"
echo "All downloads attempted."
How it works: This script reads a list of URLs from a specified text file and downloads each file to a designated destination directory. It uses `wget` for the download process and includes error handling for missing URL list files and individual download failures, making it ideal for bulk file retrieval.