6

I am trying to find if it is possible to download a part of a file (any file) via axel or aria2 or any other tools available.

For example there is a movie file (because doing this kind of thing make sense in A/V files). How could I download only the last 50MB or the 3rd 60Mb from the first of the file?

  • Are you referring to downloading using HTTP or some other protocol? – Steven D Mar 25 '14 at 6:16
  • @StevenD The files are on the http servers mostly; but could be on the ftp servers. If it is possible to download them via other protocols; there is no reason not too. – r004 Mar 25 '14 at 6:20
  • the program you were looking for: sourceforge.net/projects/prozgui – Behrooz Oct 9 '15 at 10:15
8

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.

  • in 2009 I came across a download manager named prozilla and its GUI prozgui that had the ability to do that. basically you told him to slice the file in to parts of ?mb or ?kb and then ordered it to download the Nth part. but since then that handy tool vanished without a trace. – r004 Mar 25 '14 at 8:45
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.