Skip to content

Instantly share code, notes, and snippets.

@n0kovo
Last active May 14, 2021 13:56
Show Gist options
  • Save n0kovo/db08cfcb27d47eba30910f8dd870085b to your computer and use it in GitHub Desktop.
Save n0kovo/db08cfcb27d47eba30910f8dd870085b to your computer and use it in GitHub Desktop.
Download and stream a list of remote files to a WebDAV host using cURL, showing progress using Pipe Viewer
#!/bin/zsh
url_list_file="urls.txt"
total_urls=$(wc -l < $url_list_file)
webdav_url="https://webdav.somehost.com/directory"
webdav_user="your_email@gmail.com"
webdav_pass="YourPassword"
http_cookie_header="Cookie: foo=bar; bar=foo"
count=1
while read url
do
uri=$(basename $url);
filename=$(echo $uri | cut -f1 -d"?")
echo ""
echo "Downloading and uploading file: $filename"
filesize=$(curl -H $http_cookie_header -sI $url | grep -i Content-Length | awk '{print $2}' | grep -o '[0-9]\+')
echo "Total size: $(numfmt --to si $filesize)"
curl -s $url -H $http_cookie_header | pv -s $filesize | curl -T - "$webdav_url/$filename" --user "$webdav_user:$webdav_pass";
printf "Total progress: %.2f%% ($count/$total_urls)\n" "$(bc <<< "scale=2; $count / $total_urls * 100")"
let "count=count+1";
done < $url_list_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment