Always Remember: With Gusto Comes Data Loss.

How to use LFTP

This guide is going to cover using LFTP as an FTP client. The primary reason for using LFTP over something like Transmit is because it supports file segmentation. I will first give a very brief explanation of what file segmentation is, how it differs than normal transfers, and how it may help you. I am placing this description behind a spoiler tag to allow people only interested in the LFTP syntax to easily skip past it.

 

Spoiler Inside: What is segmentation and why would I need it? Show

 
 

Using LFTP
LFTP is a command line FTP utility, meaning you will be using Terminal to work with it. For this guide I will be assuming you are going to download to the ~/Downloads folder, but you can obviously choose any location you wish. The first step is, of course, installing LFTP. The easiest way to do this is by using either Homebrew or MacPorts. The commands to install it are:

brew install lftp
port install lftp

Once installed, you will want to navigate to the directory you wish to download files into:

cd ~/Downloads

 
 

Connecting with LFTP
Now you can connect to your FTP server using the following command. Once you press enter it will attempt to connect then ask you for your password. Once you enter that, you should be connected.

lftp ftp://ftp.yourserver.com

If you plan to be using this connection a lot, you may want to create a bookmark for connecting (it can even save your password). You can have this bookmark point to any location on the server that you choose. Just navigate to the directory on the server you wish to bookmark, then enter the following commands:

set bmk:save-passwords true
bookmark add server

Now anytime you want to connect to this server you will use the command

lftp server

You can see any bookmarks you have created by using the command

bookmark list

 
 

Navigating with LFTP
Like most people, you will probably need to be able to move around in LFTP, both locally and on the remote server. The remote server behaves exactly as you are used to in Terminal, utilizing the commands

cd
ls

To navigate locally, you use the following commands

lcd
!ls

So if you want to download files to your Desktop instead of Downloads folder, you would use the command

lcd ~/Desktop
!ls

 
 

Basic File Transfers
Now to the meat of what you are looking for. LFTP uses two commands for file downloads, pget and mirror. pget is used for individual files, while mirror is used for directories.

To download the file “foo.mp3” you would use the command

pget foo.mp3

If you want to download the entire folder “bar” use the command

mirror bar

This will transfer these files into your current local directory (the one use set with lcd). The commands for uploading files and folders are very similar: put and mirror –R

If you were interrupted in the middle of a download, you can add the –c flag to pick up where it left off:

pget -c foo.mp3
mirror -c bar

 
 

File Segmentation
For this guide, I am going to follow the example given in the first section and assume you want to segment the files into 20 pieces. You can make this number as low or as high as makes sense for your environment. Segmentation is only done on files, not directories, so the mirror command will look a little more complex:

pget -n 20 foo.mp3
mirror --use-pget-n=20 bar

You can add downloads to the background (allowing you to continue browsing and starting other downloads) using the queue command:

queue pget -n 20 foo.mp3

Once you have placed downloads into the background you can see their progress by typing:

jobs -v

 
 

Parallel Downloading
The default behavior of the mirror command is to download 1 file at a time to completion before moving on to the next file in the directory. You can change this by using the -P flag to tell the program to download multiple (i.e. 5) files in parallel. The syntax for this would be:

mirror -P 5 bar

You can even combine this command with the segmentation command to tell the program to download multiple files in multiple parts simultaneously:

mirror -P 5 --use-pget-n=20 bar

 
 

And that’s it – now go forth and stick it to your ISP and their shitty peering! Though a word of warning – if you great bandwidth on the FTP server and marginal bandwidth on your local connection, it is very easy to DOS yourself by saturating all of your bandwidth with FTP traffic.

Leave a comment

Your email address will not be published. Required fields are marked *