位元詩人 技術雜談:Fast Parallel Download with lftp

Facebook Twitter LinkedIn LINE Skype EverNote GMail Yahoo Email

I was assigned by my professor to download some RNA sequences data to my own computer for backup purpose, because the original data server will clean these data. These data are dozens gigabytes in size, but the connection speed of the network in my house is not fast. Therefore, I chose lftp to speed up the downloading rate by parallel downloading.

lftp is a sophisticated ftp/http client and a file transfer program supporting several network protocols, e.g. FTP, FTPS, HTTP, HTTPS, HFTP, FISH, SFTP, torrent file and so on. lftp can be run interactively or in batch mode. You can write simple or complex commands to run lftp in a script file.

The basic lftp command is like this:


$ lftp -e "get -c http://releases.ubuntu.com/14.04.1/ubuntu-14.04.1-desktop-amd64.iso"
{{< / highlight >}}

`get` means the action of downloading.  `-c` means continuing previous download files.

If you need to download several files, you need the command `mget`, which supports wildcard expansion.

```console
$ lftp -e "mget -c http://releases.ubuntu.com/14.04.1/*.iso"
{{< / highlight >}}

If you need to download files in parallel, replace `get` with `pget`; set `mirror:use-pget-n (number)`.

```console
$ lftp -e "set mirror:use-pget-n 3; pget -c http://releases.ubuntu.com/14.04.1/ubuntu-14.04.1-desktop-amd64.iso"
{{< / highlight >}}

If you need more commands, separate them with `;`(semicolon):

```console
$ lftp -e "get -c http://releases.ubuntu.com/14.04.1/ubuntu-14.04.1-desktop-amd64.iso; get -c http://releases.ubuntu.com/14.04.1/ubuntu-14.04-server-amd64.iso"
{{< / highlight >}}

Be aware of the risk of being banned while downloading in parallel, so use the feature in caution.  Therefore, I downloaded these data to an intermediate server and, later, fetched them to my own computer.  The intermediate server was a droplet of DigitalOcean.  The downloading speed on the droplet counts in dozens megabytes, so it wouldn't spend you too much time downloading to the droplet.  Then, you can download these data again in parallel without overloading the original data server.

The rent fee of the droplet of DigitalOcean is charged in hours, so it won't cost you too much to rent a temporatory server.  You may try DigitalOcean or other similar virtual server hosting providers like Linode.  If you need the promote code of DigitalOcean, use [this link](https://www.digitalocean.com/?refcode=bb01e632c755).
關於作者

位元詩人 (ByteBard) 是資訊領域碩士,專注於從探索到產品的開發過程,並以工具驅動的方式改善專案。喜歡以開源專案作為成果,回饋社群。

主要方向包括:自用工具的打磨 (dogfooding)、編譯器技術在工具開發中的應用,以及將研究轉化為可維護的開源成果。

除了技術之外,也喜歡日本料理和黑咖啡,偶爾自助旅行,將生活中的靈感融入技術隨筆。