Last active
May 14, 2021 13:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
url_list_file="urls.txt" | |
total_urls=$(wc -l < $url_list_file) | |
webdav_url="https://webdav.somehost.com/directory" | |
webdav_user="[email protected]" | |
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