Advanced Command Line FTP LFTP

A program for Linux that allows us to make FTP by command line more powerful than the traditional one, such as copying entire directories (doing a mirror).

Possibly we already know that to do FTP, apart from using one of the programs like Filezilla or Cute FTP, we can use the command line. The command line is generally available for any operating system and is a bit more complicated to work with than windows, but sometimes there is nothing else. For example, it is very possible that you are trying to FTP to a server that you access by telnet and only have the command line to work with.

The problem with the command line is that it doesn’t allow you to perform some useful actions, such as moving up or down an entire directory, with all its subdirectories and their contents. It is something like a get or put option that is recursive and that is in charge of traversing all the directories, downloading the data they contain.

The command that we are going to see is called LFTP and it is used to carry out a more advanced FTP. Specifically, very useful when you want to mirror an entire website to download or upload it.

The lftp command is actually a program that is usually installed on all Linux, so it is most likely that we have it installed on our server.

To get help with lftp just type:

lftp -help

This will provide us with data on the different program options. To connect to an FTP server we would write this:

See also  Discard file changes with Git

lftp -u username, password ftp.domain.com

Once inside lftp, what we are looking at is the remote server. We will appear in the root directory of the FTP service. A prompt like this will appear, where it indicates the user and the server to which we are connected:

lftp user@ftp.domain.com:~>

We can do an ls -l to know the directory information.

lftp user@ftp.domain.com:~> ls -l

We can also get help with the help command:

lftp user@ftp.domain.com:~> help

This will give us a list of commands available in lftp. Among them, we have the mirror command, which we will discuss below. If we want to get help for a specific command, we can write help, followed by the command we want to know.

lftp user@ftp.domain.com:~> help mirror

This will give us the way to use and the options of the command that we were interested in. Specifically, to make a mirror you have to say the local directory where you want to copy and the remote directory that you want to copy inside the local one.

To use the mirror command we must first write the local directory that we want to copy and then the remote directory where we want to copy it.

remote local mirror

Keep in mind that when we are inside ftp, the local computer is the computer you are connected to via lftp and the remote one is the one you originally connected to via telnet. Let’s look at another example statement:

Mirror docs html

We’re saying copy the directory called docs from the server you’re FTPing to, to the html directory on the server you were telnetting to. If the html directory did not exist, it creates it.

See also  Create a REST API, 5 minutes with json-server

mirror . .

If we put this (the two . directories) we are saying to copy everything from local to remote.

Loading Facebook Comments ...
Loading Disqus Comments ...