title: aria2 使用说明
title: aria2,aria2c,wget,linux,下载
info: aria2是一款轻量型命令行下载工具,它提供了对多协议和多源地址的支持,目前支持的协议包括HTTP(S), FTP, BitTorrent (DHT, PEX, MSE/PE), and Metalink。git
aria2能够从多个源地址,并使用多种协议进行下载,并尝试将下载带宽利用率最大化。它能够同时从HTTP(S)/FTP 和 BitTorrent下载一份数据,而且将其上传到bt集群中。经过Metalink的分块检查,aria2能够在下载过程当中自动的进行数据校验。github
虽然如今有诸如wget和curl等其余相似产品,但aria2具备两个独特的功能:sql
除aria2外,也有一些其余能够进行分片下载的工具,它们每每按照线程数分割文件,并行下载,换言之,它们不会对未完成的部分进行自适应性从新分片,当整个流程工做正常时,这个策略是能够的,但一旦存在一个线程运行很是慢,这样整个进程就须要等待该线程的执行。而aria2能够很好的处理这个状况,它能够将文件分割成1M大小的分片,当某个线程运行特别缓慢时,aria2可使用更快的线程来替换。总之,根据做者的说法,aria2是很是智能和可靠的。shell
和最初的aria工具具备一个GTK+界面不一样,aria2只提供了命令行接口,从而使得对资源的要求更小。一般它的物理内存消耗为4M(HTTP/FTP)到9M(BitTorrent),当进行bt下载且速度为2.8M/s时的cpu消耗约为6%。浏览器
当源地址存在诸如&
或*
等其余shell特殊字符时,请使用单引号或者双引号将uri包含起来。服务器
在aria2的1.10.0版中,aria2对每台主机默认使用1个链接和20MB的分块大小,因此不论在-s参数中指定任何值,他都对一台主机只会创建一个链接,须要注意的一点是这个限制是针对单个主机的,当指定了多台主机时,它会对每台主机创建一个链接。若是要使用1.9.x版中的行为,则要使用-x16 -k1M。另见man页面的 –max-connection-per-server
和 –min-split-size
。cookie
aria2默认会在开始下载前预先分配文件空间以免可能的文件碎片,但这会在部分PC上带来50%-90%的cpu消耗。当使用环境为比较新的文件系统,例如ext4,btrfs,xfs或者NTFS时,做者推荐使用–file-allocation=falloc
,这种方式会在瞬间完成大文件(数G)的空间分配而且不会带来额外的性能降低。session
若是你既没有使用cutting-edge文件系统,也没有使用linux,而且很在乎系统性能,那么可使用–file-allocation=none来关闭文件的预分配。并发
若是你忘记了这些参数的全名或者含义,把-h放在选项或者词的前面,好比aria2c -hcrypt,这样aria2就会搜索crypt相关的选项并把他的帮助打印出来,若是aria2发现使用了-h,它会在打印出帮助信息后中止运行。
aria2c http://host/image.iso
在1.10.0版中,aria2对每一个host使用一个链接,你可使用–max-connection-per-server
或 -x
来修改
aria2c -x2 http://host/image.iso
Ctrl+c
能够停止当前的下载,在一样的目录运行一样的命令能够继续原来的下载,你设置能够修改uri
,若是他们指向的是同一个文件的话。
aria2c -s2 http://host/image.iso http://mirror1/image.iso http://mirror2/image.iso
注:若是命令中uri的数量多于-s的值,如本例所示,aria2将会首先使用前两个uri,将第3个uri做为候补,若是前两个有一个下载失败,就会启用第3个
aria2c http://host1/file.zip ftp://host2/file.zip
aria2c -Z http://host/file1 file2.torrent file3.metalink
aria2c file1.torrent file2.torrent
aria2c -ifiles.txt -j5
注:-j参数指定了并发下载的数量,在输入文件中能够包含torrent文件和metelink
注:输入文件中支持添加参数,详见后续的“输入文件”章节
session
aria2c -ifiles.txt --save-session=out.txt
当ctrl+c或者aria2本身退出时,全部的错误,未完成的下载信息会保存到out.txt中,但经过aria2.addTorrent 和 aria2.addMetalink XML-RPC方式增长的下载不会保存。
aria2c -i out.txt
aria2c http://host/file.metalink
aria2c --follow-metalink=mem http://host/file.metalink
aria2c -t10 --lowest-speed-limit=4000 file.metalink
aria2c -C5 file.metalink
注:当使用metalink时,-s参数再也不起做用,须要使用-C选项
aria2c file1.metalink file2.metalink
aria2c -S file.metalink
aria2c --select-file=1-4,8 -Mfile.metalink
注:能够经过-S选择来打印metalink文件的内容
aria2c --metalink-location=JP,US --metalink-version=1.1 --metalink-language=en-US file.metali
aria2c http://site/file.torrent
aria2c --follow-torrent=mem http://site/file.torrent
aria2c -u40K /path/to/file.torrent
注:-u, –max-upload-limit用来指定最大上传速度
aria2c /path/to/file1.torrent /path/to/file2.torrent
aria2c "magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C&dn=aria2"
注:须要将magnet的地址用单引号或者双引号引发来,由于里面包含’&'字符。当使用magnet时,强烈建议打开dht选项,–enable-dht
将metadata保存成.torrent文件
aria2c --bt-save-metadata "magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C&dn=aria2"
这个命令会将metadata信息保存在248d0a1cd08284299de78d5c1ed359bb46717d8c.torrent文件中
当全部节点的总体下载速度低于某个值时,aria2能够临时增长节点数量来获取更快的下载速率
aria2c --bt-request-peer-speed-limit=200K file.torrent
aria2c --enable-dht http://site/file.torrent
注:在1.7.2版本后,dht选项是被默认打开的。当aria2只处理http/ftp下载时,不会打开dht选项。当第一个torrent开始下载时,aria2进行DHT功能的初始化,而后一直运行到aria2退出。
aria2c --enable-dht6 --dht-listen-port=6881 --dht-listen-addr6=YOUR_GLOBAL_UNICAST_IPV6_ADDR --enable-async-dns6
注:若是aria2在build时没有使用c-ares,则不须要–enable-async-dns6。aria2在ipv4和ipv6的dht中共享一些端口
下面这个例子将从file.torrent中移除全部的tracker的uri,而后使用”http://tracker1/announce” 和 “http://tracker2/announce”
aria2c --bt-exclude-tracker="*" --bt-tracker="http://tracker1/announce,http://tracker2/announce" file.torrent
在默认状况下,aria2能够接收加密/非加密的链接,而且会首先尝试加密握手,若是失败才会去使用传统的BitTorrent握手
下面这个例子中,aria2将只经过加密的握手接受与创建链接。
aria2c --bt-require-crypto=true http://site/file.torrent
存在两种加密方式,头加密和全链接加密。若是两种均可以被peer提供,aria2将默认使用头加密方式。若是要使用全链接加密,可使用:
aria2c --bt-min-crypto-level=arc4 http://site/file.torrent
aria2c -S file.torrent
aria2c --select-file=1-4,8 -Tfile.torrent
注:index信息能够经过-S来得到
aria2c --listen-port=6881-6883 file.torrent
注:请确保指定端口能够进行tcp的上行和下行通讯
aria2c --seed-time=120 --seed-ratio=1.0 file.torrent
注:本例中,aria2会在下载完成后120分钟,或seed ratio达到1.0时退出程序
aria2c --max-upload-limit=100K file.torrent
可使用-V选择来播种下载完成的文件,它会首先对文件进行分片的hash校验
Seeding already downloaded file
若是能够肯定下载文件的正确性,可使用–bt-seed-unverified选项来跳过文件的校验环节
aria2c --bt-seed-unverified -d/path/to/dir file.torrent
aria2c --bt-seed-unverified -d/path/to/dir file1.torrent file2.torrent
为了指定bt下载的文件名称,须要使用-S选线来查看torrent文件中的index信息,例如:
idx|path/length ===+====================== 1|dist/base-2.6.18.iso |99.9MiB ---+---------------------- 2|dist/driver-2.6.18.iso |169.0MiB ---+----------------------
下面的命令能够将dist/base-2.6.18.iso 保存为 /tmp/mydir/base.iso,同时将dist/driver-2.6.18.iso 保存成 /tmp/dir/driver.iso
aria2c --dir=/tmp --index-out=1=mydir/base.iso --index-out=2=dir/driver.iso file.torrent
注:当对http uri中的torrent文件使用–index-out是不成功,它只对本地的torrent文件有效。aria2也不会去记忆–index-out选项内容,在每次的继续下载或播种时都须要手工指明,并且若是没有该选项,它也不会给用户任何提醒,因此须要注意。
优先下载torrent中全部文件的前1MB
aria2c --bt-prioritize-piece=head file.torrent
aria2c --all-proxy='http://proxy:8080' http://host/file
注:–all-proxy选项能够被特定的协议选项覆盖,如–http-proxy, –https-proxy 和 –ftp-proxy
aria2c --http-proxy='http://proxy:8080' http://host/file
aria2c --http-proxy='http://proxy:8080' --http-proxy-user='username' --http-proxy-passwd='password' http://host/file aria2c --http-proxy='http://username:password@proxy:8080' http://host/file
注:username and password 须要进行%转码,如过username是’myid@domain’,则转码后的结果为:’myid%40domain’。
导入Mozilla/Firefox(1.x/2.x) 和 Netscape格式的cookie
aria2c --load-cookies=cookies.txt http://host/file
导入Firefox3格式的cookie
aria2c --load-cookies=cookies.sqlite http://host/file
被浏览器或其余程序继续下载
aria2c -c -s2 http://host/partiallydownloadedfile.zip
aria2c --max-download-limit=100K http://host/file
aria2c -V file.metalink
注:这个选项只适用于BitTorrent或者带有校验的metalink
aria2c --lowest-speed-limit=10K file.metalink
可使用大括号来表达一组列表
aria2c -P http://{host1,host2,host3}/file.iso
可使用[]来表示一个数字序列
aria2c -Z -P http://host/image[000-100].png
注:当全部的URI指向不一样的文件时,须要使用-Z选项
甚至能够指定步长
aria2c -Z -P http://host/image[A-Z:2].png
保留源文件时间戳
aria2c -R http://host/file.iso
下载完成后执行特定命令
aria2c --on-download-complete=COMMAND http://example.org/file.iso
另见:–on-download-error
, –on-download-start
和 –on-download-stop
,或者执行aria2c -h#hook
写入/dev/null
aria2c -d /dev -o null --allow-overwrite=true http://example.org/file
–allow-overwrite=true
是为了不aria2重命名已有的/dev/null
输入文件中能够包括一系列的URI地址,也能够针对同一个资源设置多个URI:不一样的URI写在一行并使用tab分割。
输入文件的每一行都被看成aria2的命令行参数,所以能够受到-Z和-P选项影响
另外,选项也能够在每行URI的后面设置,更详尽的描述能够在man page的输入文件部分获得。这种选择的含义与命令行选项的含义一致,不过只适用在他们跟随的那个URI上。
以下,一个uri文件名为uri.txt,其内容以下:
http://server/file.iso http://mirror/file.iso dir=/iso_images out=file.img http://foo/bar
若是aria2使用 -i uri.txt -d /tmp
,
那么file.iso就会被保存为/iso_images/file.img,
它的下载源为http://server/file.iso 和 http://mirror/file.iso ;
而bar文件则是从http://foo/bar 下载而且保存为 /tmp/bar
*[uri]: 远程或者本地文件地址
来源:https://raw.githubusercontent.com/erasin/notes/master/linux/soft/aria2.md