我使用wget下载网站内容,但是wget是一个一个下载文件的。

我怎么能让wget下载使用4个同时连接?


当前回答

使用咏叹调2:

aria2c -x 16 [url]
#          |
#          |
#          |
#          ----> the number of connections 

http://aria2.sourceforge.net

其他回答

考虑使用正则表达式或FTP Globbing。通过这种方法,您可以使用不同的文件名起始字符组多次启动wget,这取决于它们出现的频率。

这是我如何在两个NAS之间同步文件夹的例子:

wget --recursive --level 0 --no-host-directories --cut-dirs=2 --no-verbose --timestamping --backups=0 --bind-address=10.0.0.10 --user=<ftp_user> --password=<ftp_password> "ftp://10.0.0.100/foo/bar/[0-9a-hA-H]*" --directory-prefix=/volume1/foo &
wget --recursive --level 0 --no-host-directories --cut-dirs=2 --no-verbose --timestamping --backups=0 --bind-address=10.0.0.11 --user=<ftp_user> --password=<ftp_password> "ftp://10.0.0.100/foo/bar/[!0-9a-hA-H]*" --directory-prefix=/volume1/foo &

第一个wget同步所有以0,1,2…开头的文件/文件夹。F, G, H和第二个线程同步所有其他内容。

这是在带有一个10G以太网端口(10.0.0.100)的NAS和带有两个1G以太网端口(10.0.0.10和10.0.0.11)的NAS之间进行同步的最简单方法。我通过——bind-address将两个wget线程绑定到不同的以太网端口,并通过在每行末尾放置&将它们称为并行。通过这种方式,我能够复制2x 100mb /s = 200 MB/s的大文件。

使用咏叹调2:

aria2c -x 16 [url]
#          |
#          |
#          |
#          ----> the number of connections 

http://aria2.sourceforge.net

使用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的值是多少,它都只会在单个连接中运行

尝试pcurl

http://sourceforge.net/projects/pcurl/

使用curl代替wget,并行下载10段。

为每个链接调用Wget并将其设置为在后台运行。

我尝试了这段Python代码

with open('links.txt', 'r')as f1:      # Opens links.txt file with read mode
  list_1 = f1.read().splitlines()      # Get every line in links.txt
for i in list_1:                       # Iteration over each link
  !wget "$i" -bq                       # Call wget with background mode

参数:

      b - Run in Background
      q - Quiet mode (No Output)