Aria2c多线程带cookie下载

2,985 阅读2分钟

Aria2c多线程带cookie下载

相对于curl,wget等下载工具,aria2c具有多线程下载的功能,是我选用的主要原因。除此之外aria2c还可以下载磁力和种子文件,还有rpc远程控制端口。aria2c的基本选项和wget很像,让人感到熟悉容易理解。

安装

sudo apt install aria2c

使用

直接下载如aria2c 'http://xxx',同时也提供了丰富的可选配置选项。

例子:

aria2c -x 8 -k 10M -d ./ -o foo.txt  --load-cookies  ./cookies.txt --header='Referer: http://xxx' 'http://xxx'

参数:

  • aria2c:命令
  • -x 8:最大下载线程
  • -k 10M:最小线程块大小,文件大小每大于该值大小就新建线程,直到最大数量。
  • -d ./:下载目录
  • -o foo.txt :下载文件名
  • --load-cookies ./cookies.txt:从文件读取cookie,文件内容是请求头里的cookie字段。比如登录后才能访问的链接需要附带cookie的登录状态来请求。
  • --header='Referer: http://xxx' :附带的请求头部信息,比如来源地址等。
  • http://xxx’:下载链接,需要引号,防止sh误解析成命令。

获取请求cookie,格式类似于“a=10; b=5;”:

运行:

解释:

  • CN:连接数
  • DL:当前下载速度

官方文档(部分)

aria2c(1)
SYNOPSIS
aria2c [<OPTIONS>] [<URI>|<MAGNET>|<TORRENT_FILE>|<METALINK_FILE>] ...

OPTIONS
-d, --dir=<DIR>
The directory to store the downloaded file.

-x, --max-connection-per-server=<NUM>
The maximum number of connections to one server for each download. Default: 1

-k, --min-split-size=<SIZE>
aria2 does not split less than 2*SIZE byte range. For example, let's consider downloading 20MiB file. If SIZE is 10M, aria2 can split file into 2 range [0-10MiB) and [10MiB-20MiB) and download it using 2 sources(if --split >= 2, of course). If SIZE is 15M, since 2*15M > 20MiB, aria2 does not split file and download it using 1 source. You can append K or M (1K = 1024, 1M = 1024K). Possible Values: 1M -1024M Default: 20M

-o, --out=<FILE>
The file name of the downloaded file. It is always relative to the directory given in --dir option. When the --force-sequential option is used, this option is ignored.

--referer=<REFERER>
Set an http referrer (Referer). This affects all http/https downloads. If * is given, the download URI is also used as the referrer. This may be useful when used together with the --parameterized-uri option.

--header=<HEADER>
Append HEADER to HTTP request header. You can use this option repeatedly to specify more than one header:
$ aria2c --header="X-A: b78" --header="X-B: 9J1" "http://host/file"

--load-cookies=<FILE>
Load Cookies from FILE using the Firefox3 format (SQLite3), Chromium/Google Chrome (SQLite3) and the Mozilla/Firefox(1.x/2.x)/Netscape format.

总结

Aria2c提供了非常丰富选项,能够满足多线程,带cookie等的下载需求。功能全面,值得一用。

参考

  1. Aria2 Manual — aria2 1.35.0 documentation