This brief but detailed guide will explain how to use ncftp in Linux to recursively copy files from an FTP site.
The other day I was migrating my hosting from one server to another. My previous hosting only gave me FTP access. The new host came enabled with SSH and a complete Linux environment. I wanted to migrate the data from my old host to the new one. Here’s how I moved all my data.
I used the following command for the migration:
# ncftpget -R -v -u “remoteuser” -p “password” ftp://remotserver.com /home/localdir /remotedir
NC FTP is a really cool FTP client for the Linux command line. It ships by default with most Linux distributions. It comes installed with a few command such as ncftpget and ncftpput. In this example we’re using the first of the two commands. Here’s a breakup of the command.
-R -v These two tell ncftpget to get the files recursively, and make the output verbose.
-u -p These two parameters are followed by the username and password for the FTP session.
ftp://remotserver.com This is the IP address or the domain of the remote FTP server.
/home/localdir This is the path of the directory in your local machine where you want to copy the remote files
/remotedir This is path of the directory you want to copy in the remote server
Just be careful not to mix up the local and remote directories when you run the command. Otherwise, it should be pretty straightforward.
If you’re looking for a more graphical approach for creating backups via FTP, check out our guide on how to create and restore backups in Ubuntu – although it works in any Linux environment running Gnome, not just Ubuntu.