發新話題

Linux下使用 lftp 多線程下載(SSH超快!)pget

Linux下使用 lftp 多線程下載(SSH超快!)pget

每次在linux下用wget感覺速度還是比較慢,關鍵是wget不支持多線程。對於喜歡命令行操作及追求高效率、高速度下載的朋友,推薦使用命令行下載工具lftp命令行工具不但使用方便,而且大多具有很高的下載速度及下載效率,尤其適合於大批量下載文件。linux命令行下的多線程下載工具呢?答案是有的。lftp就是這樣一個工具,可以這樣來使用。
lftp是極強大的ftp客戶端工具,也是我們這些系統管理員工具箱中的利器
lftp的官方站:
http://lftp.yar.ru/
redhat系列的發行版默認已安裝此軟件,
你可以用whereis lftp進行檢查,如找不到此命令,
則可以用 yum install lftp進行安裝

它可以支持多線程下載文件:
lftp -c 'pget -n 10 http://www.dk101.com/xxx.mp3'
參數的含義:
-c 執行完給出的命令後退出
pget 把文件分為多份(多少份?就是-n指定的數量)後再進行下載,
下載時會啟動 -n參數所指定數量的線程
-n 指定線程數量

多學一點東東:
a,如果需要指定文件下載到本地後的路徑或文件名時如何處理?
lftp -c 'pget -n 10 http://www.dk101.com/xxx.mp3 -o /home/lhd/music/a.mp3'
-o 指定下載到本地後的文件名
b,如何做到斷點續傳?
在pget上用-c參數:
-c:continue transfer
如下:
lftp -c 'pget -n 10 -c http://www.dk101.com/xxx.mp3 -o /home/lhd/music/a.mp3'

  [root@AS5 ~]# lftp -c "pget -n 10 http://downloads.sourceforge.net/kvm/kvm-17.tar.gz"

  這樣就指定線程為10個(pget -n 10),並且斷點續傳(-c)。

  [root@AS5 ~]# lftp -v

  LFTP | Version 3.5.1 | Copyright (c) 1996-2006 Alexander V. Lukyanov

  LFTP is free software, covered by the GNU General Public License, and you are

  welcome to change it and/or distribute copies of it under certain conditions.

  There is absolutely no warranty for LFTP. See COPYING for details.

  Send bug reports and questions to .

  Libraries used: Readline 5.1

  可以看看它的 man 文檔,說明如下:

  ############################

  pget [OPTS] rfile [-o lfile]

  Gets the specified file using several connections. This can speed up transfer,

  but loads the net and server heavily impacting other users.

  Use only if you really have to transfer the file ASAP. Options:

  -c continue transfer. Requires lfile.lftp-pget-status file.

  -n maxconn set maximum number of connections (default is taken from pget:default-n setting)

  ##############################

  真的很不多,大家可以試試。多看看man手冊,會有很多收穫哦。
----------------------------------------------------------------------
Linux 於 Shell 使用 lftp 來同時開啟多個連線下載

Windows 以前常用 Flashget, 主要是有些網站會限制 單一 Thread 的下載速度, 所以要多開幾個連線去存取.

在 Linux 的 Bash shell (command line) 要如何做到 多 thread 下載 呢?

要能自動將 檔案分割, 且支援 多連線下載, 可以使用 lftp 來達成~
lftp pget 使用說明

詳細 lftp 說明可見: lftp - DebianWiki (下述說明轉載於此頁)

    pget [OPTS] <rfile> [-o <lfile>]
    使用多個連結來下載檔案, 預設為五個。
    -n 3 為三個連結

ex: lftp -e 'pget -n 5 http://dk101.com/xxx.iso'
多線下載範例

    * 抓 Ubuntu 9.10 ISO:
lftp -e 'pget -n 5 http://releases.ubuntu.com/releases/9.10/ubuntu-9.10-beta-desktop-i386.iso'
    * 抓 Linux kernrl Source:
lftp -e 'pget -n 5 http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.gz'
----------------------------------------------------------------------------------------
相關網頁:
Home > CentOS
lftp to accelerate ftp / http download speed under Linux and UNIX

by Vivek Gite · 4 comments

lftp is a file transfer program that allows sophisticated ftp, http and other connections to other hosts. If site is specified then lftp will connect to that site otherwise a connection has to be established with the open command. This is an essential tool for all a Linux admin. I've already written about Linux ultra fast command line download accelerator such as Axel and prozilla. lftp is another tool for same job with more features.

lftp can handle seven file access methods :
=> ftp
=> ftps
=> http
=> https
=> hftp
=> fish
=> sftp
=> file
So what's special about lftp?

    * Every operation in lftp is reliable, that is any not fatal error is ignored and the operation is repeated. So if downloading breaks, it will be restarted from the
      point automatically. Even if ftp server does not support REST command, lftp will try to retrieve the file from the very beginning until the file is transferred completely.
    * lftp has shell-like command syntax allowing you to launch several commands in parallel in background
    * lftp has builtin mirror which can download or update a whole directory tree. There is also reverse mirror (mirror -R) which uploads or updates a directory tree on server. Mirror can also synchronize directories between two remote servers, using FXP if available.

Use lftp as download accelerator

lftp has pget command. It allows you download files in parallel. lftp pget command syntax:
lftp -e 'pget -n 5 ftp://path/to/file'

For example, download http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.2.tar.bz2 file using pget in 5 parts:
$ cd /tmp
$ lftp -e 'pget -n 5 http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.2.tar.bz2'
Output:

45108964 bytes transferred in 57 seconds (775.3K/s)
lftp :~>quit

A note about parallel downloading

Please note that by using download accelerator you are going to put a load on remote host. Also note that lftp may not work with sites that do not support multi-source downloads or blocks such requests at firewall level.

lftp command offers many other features. Refer to lftp man page for more information:
man lftp

[ 本帖最後由 青翁道人 於 2010-2-7 14:58 編輯 ]

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。