This is one of the top Google results for this question so I wanted to share this solution which works for me in the hopes it helps some future traveller on the Internets (tweak as needed) =>
#!/bin/bash
# Path to the iCloud folder you want to keep downloaded
folder_path="$HOME/Library/Mobile Documents/com~apple~CloudDocs/iCloudFolderYouWantToSync"
# Log file for debugging
log_file="$HOME/icloud_download.log"
# Clear previous log
echo "Log started on $(date)" > "$log_file"
# Check if the folder exists
if [ ! -d "$folder_path" ]; then
echo "Folder $folder_path does not exist" >> "$log_file"
exit 1
fi
# Find all files in the folder recursively
files=$(find "$folder_path" -type f)
# Check if files were found
if [ -z "$files" ]; then
echo "No files found in $folder_path" >> "$log_file"
exit 1
fi
# Force download each file
echo "$files" | while read -r file; do
echo "Downloading $file" >> "$log_file"
brctl download "$file" >> "$log_file" 2>&1
if [ $? -ne 0 ]; then
echo "Failed to download $file" >> "$log_file"
fi
done
echo "Script finished on $(date)" >> "$log_file"
Add this to your crontab via "crontab -e":
0 * * * * /path/to/keep_icloud_downloaded.sh
this will keep all files in all subfolders of the given folder downloaded every hour)