Issue
The cURL's manpage, https://curl.se/docs/manpage.html#-r
, explains how to use the --range
option.
--range 0-499 specifies the first 500 bytes
--range 500-999 500-999 specifies the second 500 bytes
--range -500 specifies the last 500 bytes```
My current file:
$ curl -so Zorin-OS-16.2-Core-64-bit.iso https://mirror.freedif.org/zorin/16/Zorin-OS-16.2-Core-64-bit.iso
$ du -b Zorin-OS-16.2-Core-64-bit.iso
3071934464
Of course without splitting the file, for example, using the split tool on Linux, please teach me the best way to divide the 3071934464
into 3, or 4 range parts, of course at the correct position, then put them into a readarray
, or variable, or text file, so that I can apply them to the command loop, of course in Linux shell.
curl -k -v -i -X PUT -T 'Zorin-OS-16.2-Core-64-bit.iso' -H 'Content-Length: xxxx' --range 0-xxxx
curl -k -v -i -X PUT -T 'Zorin-OS-16.2-Core-64-bit.iso' -H 'Content-Length: xxxx' --range xxxx-xxxx
curl -k -v -i -X PUT -T 'Zorin-OS-16.2-Core-64-bit.iso' -H 'Content-Length: xxxx' --range xxxx-xxxx
curl -k -v -i -X PUT -T 'Zorin-OS-16.2-Core-64-bit.iso' -H 'Content-Length: xxxx' --range -xxxx
Note: If I don't use the Content-Length:
option, the message 413 Request Entity Too Large
appears.
Solution
You could calculate the range part then store them in a bash
array, you might need to adjust the script below according to your requirements but it will give you an idea
#!/bin/bash
total_size=3071934464
num_parts=4
part_size=$((total_size / num_parts))
ranges=()
for ((i=0; i<num_parts-1; i++)); do
start=$((i * part_size))
end=$(((i + 1) * part_size - 1))
ranges+=("$start-$end")
done
# Add the last part
ranges+=("$((part_size * (num_parts - 1)))-")
for range in "${ranges[@]}"; do
echo "Uploading range $range"
curl -k -v -i -X PUT -T 'Zorin-OS-16.2-Core-64-bit.iso' -H "Content-Length: $part_size" --range "$range"
done
Answered By - Saxtheowl Answer Checked By - Senaida (WPSolving Volunteer)