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