How to install lftp on FreeBSD using the CLI

I need to download a large file and get the specified file using several connections to speed up downloads on FreeBSD. How do I install lftp and download files using FreeBSD?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements FreeBSD
Est. reading time 3 minutes
lftp is a sophisticated file transfer program. It supports HTTPS, FTP/FTPS/SFTP, HTTP, and other connections to other hosts. Besides FTP-like protocols, lftp has support for BitTorrent protocol too. Seeding is also supported. This page explains how to install lftp on the FreeBSD cloud system (server or jail) to grab large files using multiple connections.

Installing lftp on FreeBSD

  1. Open the terminal application and then run the following command to install lftp on your FreeBSD box.
  2. First, make sure the pkg database is up to date:
    sudo pkg update
  3. Apply any pending updates to the FreeBSD box:
    sudo pkg upgrade
  4. Search for lftp package:
    sudo pkg search lftp
  5. Note down the lftp version and then try to grab information about the lftp package on FreeBSD:
    sudo pkg search -f lftp-4.9.2
    How to search lftp package on FreeBSD Unix system

    Searching for lftp on FreeBSD

  6. Finally install lftp on FreeBSD using the pkg command:
    sudo pkg install lftp
    Installing lftp on FreeBSD using the pkg command
  7. Alternatively, we can install it via the port as root user:
    cd /usr/ports/ftp/lftp/ && make install clean

lftp command syntax

The syntax is:
lftp url
lftp [option] url
lftp -e 'command1; get url; exit'

For example, if you type the following command, it will not download anything:
lftp get https://www.cyberciti.biz/files/adduser.txt
Here is what I see:

cd ok, cwd=/files/adduser.txt                                     
lftp www.cyberciti.biz:/files/adduser.txt>

By default, lftp is interactive. We need to issue commands. So my sample session would be:
lftp
Now we will see lftp :~> prompt. To retrieve/download remote file, use the get command:
lftp :~> get https://www.cyberciti.biz/files/adduser.txt
Then exit from lftp or move to background if jobs are active. Type either exit or quit. The quit commnand is a built-in alias for exit:
lftp :~> exit
However, we can automate download procdure by passing the -e to lftp client:
lftp -e 'get https://www.cyberciti.biz/files/adduser.txt; exit'
Downloading files with lftp on FreeBSD box
Now it is much more straightforward and easy to use.

lftp examples

lftp has shell-like command syntax allowing you to launch several commands in parallel in the background. The syntax is:
pget url
pget -c url
pget -c -n 10 url
pget -c -n 10 -O base_dir url

Where,

  • -c : Continue or resume broken transfer.
  • -n {maxconn} : Set maximum number of connections when downloading files to accelerator download speed.
  • -O {base_dir} : Specifies base directory where files should be placed

For example, we can download FreeBSD 13 ISO for bhyve VM as follows using the lftp:

URL="https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/13.0/FreeBSD-13.0-RELEASE-amd64-dvd1.iso"
lftp -e "pget -c -n 20 ${URL}; exit;"

lftp example
We can use the shasum command to verify and checksum for downloaded FreeBSD ISO file:
shasum --ignore-missing -c CHECKSUM.SHA512-FreeBSD-13.0-RELEASE-amd64
I saw confirmation as follows:

FreeBSD-13.0-RELEASE-amd64-dvd1.iso: OK

Next, I am going to set up FreeBSD VM under bhyve. But that will be another tutorial someday.

Summing up

The lftp client is my go-to download for both Linux and FreeBSD, including macOS. Please try out lftp. lftp has many more options. Hence, make sure your read man page/documentations by typing the following man command:
man lftp


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum