我使用wget下载网站内容,但是wget是一个一个下载文件的。
我怎么能让wget下载使用4个同时连接?
我使用wget下载网站内容,但是wget是一个一个下载文件的。
我怎么能让wget下载使用4个同时连接?
当前回答
我强烈建议使用httrack。
例如:httrack -v -w http://example.com/
默认情况下,它将使用8个同时连接创建镜像。Httrack有很多游戏地点可供选择。看一看。
其他回答
为了加快文件下载速度,Wget不支持多个套接字连接。
我想我们可以给出比格里安更好的答案。
正确的方法是使用aria2。
aria2c -x 16 -s 16 [url]
# | |
# | |
# | |
# ---------> the number of connections here
官方文档:
-x,——max-connection-per-server=NUM:每次下载到一台服务器的最大连接数。取值范围:1 ~ 16。默认值:1
-s,——split=N:使用N个连接下载文件。如果提供了超过N个uri,则使用前N个uri,其余url用于备份。如果给出的uri少于N个,则这些url将被使用不止一次,以便同时建立总共N个连接。到同一主机的连接数量由——max-connection-per-server选项限制。另参见——min-split-size选项。取值范围:1-*默认值:5
use
aria2c -x 10 -i websites.txt >/dev/null 2>/dev/null &
在sites.txt中每行放一个url,例如:
https://www.example.com/1.mp4
https://www.example.com/2.mp4
https://www.example.com/3.mp4
https://www.example.com/4.mp4
https://www.example.com/5.mp4
正如其他海报所提到的,我建议你看一看aria2。Ubuntu 1.16.1版本的手册页:
aria2 is a utility for downloading files. The supported protocols are HTTP(S), FTP, BitTorrent, and Metalink. aria2 can download a file from multiple sources/protocols and tries to utilize your maximum download bandwidth. It supports downloading a file from HTTP(S)/FTP and BitTorrent at the same time, while the data downloaded from HTTP(S)/FTP is uploaded to the BitTorrent swarm. Using Metalink's chunk checksums, aria2 automatically validates chunks of data while downloading a file like BitTorrent.
您可以使用-x标志来指定每个服务器的最大连接数(默认为1):
aria2c -x 16 [url]
如果同一文件可从多个位置下载,则可以选择从所有位置下载。使用-j标志指定每个静态URI的最大并行下载数量(默认为5)。
aria2c -j 5 [url] [url2]
更多信息请访问http://aria2.sourceforge.net/。对于使用信息,手册页是真正的描述性的,并在底部有一个小节提供了使用示例。在线版本可以在http://aria2.sourceforge.net/manual/en/html/README.html上找到。
使用xargs使wget在多个文件中并行工作
#!/bin/bash
mywget()
{
wget "$1"
}
export -f mywget
# run wget in parallel using 8 thread/connection
xargs -P 8 -n 1 -I {} bash -c "mywget '{}'" < list_urls.txt
Aria2选项,正确的工作方式与文件小于20mb
aria2c -k 2M -x 10 -s 10 [url]
-k 2M将文件分割成2mb的块
-k或——min-split-size的默认值是20mb,如果你不设置这个选项并且文件小于20mb,无论-x或-s的值是多少,它都只会在单个连接中运行
另一个可以做到这一点的程序是axel。
axel -n <NUMBER_OF_CONNECTIONS> URL
对于基本的HTTP认证,
axel -n <NUMBER_OF_CONNECTIONS> "user:password@https://domain.tld/path/file.ext"
Ubuntu手册页。