Download Files from FTP Server with lftp

Why is this useful? Let’s consider a scenario where your provider only supports FTP and no other protocols. Additionally, you might have a headless server where you need to transfer your data. The data set is enormous, and it would be inefficient to download it to your local PC and then re-upload it to the new server; that would be a waste of time. Utilizing lftp to download files from FTP directly to the server can be incredibly beneficial, as it not only overcomes the protocol limitation but also saves you valuable time in the process.

Installation

Arch and it’s derivatives:

sudo pacman -S lftp

Ubuntu and it’s derivatives:

sudo apt install lftp

Usage

After installation, the first thing you need to do is to login to the remote FTP server with lftp.

lftp -u "USERNAME","PASSWORD" HOST_URL

Change USERNAME, PASSWORD, and HOST_URL to your exact FTP server credentials.

Your host can be a domain or IP. Additionally, you can specify a different port using the -p flag.

To obtain more information about options, type: lftp --help.

Example command would be:

lftp -u "user1","hdn32jhksks" ftp.myhost.com

Once connected, you can download files using the pget command.

pget file1.md

This will download file1.md to the current directory you are in.

You can also download multiple files at a time with:

pget file1.md file2.md invoice.pdf

I don’t think so, you might prefer to use lftp for this simple file download as mentioned above. What if you have numerous directories and files, some of them quite large? In that case, you can utilize the mirror command, which will recursively download all of them to your specified path.

mirror site_migration /home/Downloads

The above command will download the site_migration directory to your local /home/Downloads directory. This operation is recursive, meaning that all files and directories inside site_migration will be downloaded as well.

Nextcloud_Logo

Looking to install Nextcloud 27 (Hub 5) on Ubuntu? Click here