Date Posted: 31-01-2018

In this Post we will explain How to Setup lftp – A Simple Command Line FTP Program.

This article is about Lftp and how we can install Lftp in our Linux Operating System. Lftp is a command line based File Transfer Software also known as FTP Client.

Installing Lftp

On Ubuntu

In Ubuntu  and its derivatives, we can install lftp using apt manager. So, to install it, we’ll need to run the following commands in a shell or a terminal under sudo privilege.

$ sudo apt-get install lftp

On CentOS/Fedora/RHEL

As lftp is also available in the repository of Fedora, CentOS and RHEL, we can use yum manager to install it.

$ sudo yum install lftp

Connecting to your FTP server

To login to a ftp server or sftp server, make sure you know your FTP username and your server hostname. Once you have those you can simply connect to your FTP server by running:

$ lftp ftp://username@hostname

Navigation

We can use ‘ls’ to list files and directories, ‘cd’ to enter into a directory.

Uploading and Download Files

Pget command

We can use pget for downloading files from the remote server.

$ pget file_from_server.txt

Put command

We can use put for uploading files to the remote server.

$ put file_from_workspace_file.txt

Reverse mirroring of directory

If we want to mirror entire directory to the server, we will use reverse mirror command.

lftp user@ip:~> mirror -R

This is used to copy local directory contenets to the server.

Exiting the shell

Bye command is used to exit from the lftp shell

Using LFTP commands as part of the script

After we exited the LFTP, we can use above commands without logging onto ftp server. That way you can embed it into bash script.

$ lftp -e ‘mirror /home/user/ /home/user/Videos/’ -u user,password ftp://ip

Leave a Reply