49

I need to download everything from an FTP server to hosting on a different server. I have shell access only to the server I'm downloading the files to. How, using the Linux FTP command, can I download every file, creating the directories needed for them in the process?

Navarr
  • 3,703
  • 7
  • 33
  • 57

3 Answers3

93

Use wget in this manner (m for mirroring):

wget -m ftp://username:password@ip.of.old.host

If your username or password contains special characters, you may need to use the format:

wget -m --user=username --password=password ftp://ip.of.old.host

Alternatively, I found this guide which shows you how to do it using ncftp in Debian. You will require root access to the new server if ncftp is not installed already.

In short:

sudo apt-get install ncftp
ncftpget –T –R –v –u "ftpuser" ftp.nixcraft.net /home/vivek/backup /www-data
Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
  • Thanks. I actually had found it myself right before seeing this. Wasn't using the right google search terms the first five times. – Navarr Jun 09 '10 at 05:03
  • 3
    If you get a "bad port" error message you may have an email address as username (the internet is getting weird) and the @ is confusing wget. Try: wget -m --user some.email@example.com --password myPassword ftp://example.com – Rob Drimmie Jan 05 '15 at 16:31
  • When the password has '@' at the end this does not work. Is there an alternative? – A. K. May 27 '15 at 01:40
3

Another way is to use ftp. Here's an example shell script using ftp:

#! /bin/bash

ftp -n << 'EOF'
open ftp.your_ftp_host.com
quote USER your_username_here
quote PASS your_password_here
cd gets
prompt no
mget * .
bye
EOF
mgoldwasser
  • 14,558
  • 15
  • 79
  • 103
1

Some FTP servers allow to download whole directories by suffixing their name with .tar or .tgz. The server then creates an archive of that directory.

mouviciel
  • 66,855
  • 13
  • 106
  • 140