How to recursively copy files from an FTP server with Linux

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.

Leave a Comment

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