Download Only a Part of a File
Whether or not you can download a portion of a file depends on the protocol being used to transfer the content.
If the files are available over HTTP/1.1, then any server that correctly supports the Range header (see section 14.35 of RFC 2616) should allow you download portions of the file.
Consider the following file:
$ cat testfile.txt
12345
If I serve this up with nginx, a webserver that supports the Range header, I can download portions of it (newlines inserted for readability):
$ curl --header "Range: bytes=2-3" https://localhost/testfile.txt -k
34
$ curl --header "Range: bytes=0-1" https://localhost/testfile.txt -k
12
$ curl --header "Range: bytes=4-" https://localhost/testfile.txt -k
5
This is the same feature that curl, wget, and other HTTP clients use to "resume" interrupted transfers.
The FTP protocol provides resuming a file transfer at a given offset via the RESTART (REST) command (See section 4.1.3 of RFC 959). Using the same testfile.txt as above, served by FTP:
$ touch testfile.txt
$ ftp localhost
Connected to localhost.
220 (vsFTPd 2.2.2)
Name (localhost:steve): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> rest 3
restarting at 3. execute get, put or append to initiate transfer
ftp> get testfile.txt
local: testfile.txt remote: testfile.txt
200 PORT command successful. Consider using PASV.
350 Restart position accepted (3).
150 Opening BINARY mode data connection for testfile.txt (6 bytes).
226 Transfer complete.
3 bytes received in 0.00 secs (19.1 kB/s)
ftp> 221 Goodbye.
$ cat testfile.txt
45
I'm not familiar with many FTP clients so I don't know if any do this, but it would likely be possible to read any subset of bytes by using the REST command and then simply stoping once you have the number of bytes you want.
It appears that aria2
is capable of resuming both HTTP and FTP transfers with the -c
flag. This likely uses the features above as it is only supported for HTTP and FTP. However, it does not appear to natively support downloading only the end or middle segment of a file. It could be possible to exploit the --continue
flag by creating a dummy file on disk. If this file had N bytes, perhaps aria would start at the N+1 byte of the file.
curl
has --range
/-r
switch, which is documented to support both HTTP and FTP (and even SFTP) protocols:
curl --range start-end ftp://example.com/file.ext --output test.ext