Linux: Download all file from ftp server recursively

by nixcraft on April 27, 2005 · 15 comments

You can use ncftpget command to download entire ftp directory and sub directories from remote ftp server. Let us say you would like to download /www-data directory and all subdirectories inside this one from ftp.nixcraft.net server. You need to use ncftpget command.

Install ncftp client

ncftp client software can be downloaded from http://www.ncftp.com/ncftp/ and works with FreeBSD, Solaris and all most all UNIX variant. You can also run command as follows to install ncftp:
$ sudo apt-get install ncftp

FTP get directory recursively

ncftpget is Internet file transfer program for scripts and advance usage. You need to use command as follows:
$ ncftpget –R –v –u "ftpuser" ftp.nixcraft.net /home/vivek/backup /www-data
Where,

  • -R : Copy all subdirectories and files (recursive)
  • -v : Verbose i.e. display download activity and progess
  • -u "USERNAME" : FTP server username, if skipped ncftpget will try anonymous username
  • ftp.nixcraft.net : Ftp server name
  • /home/vivek/backup : Download everything to this directory
  • /www-data : Remote ftp directory you wish to copy

If you get an error which read as follows:

tar: End of archive volume 1 reached
tar: Sorry, unable to determine archive format.
Could not read directory listing data: Connection reset by peer

Then add –T option to ncftpget command:

$ ncftpget –T –R –v –u "ftpuser" ftp.nixcraft.net /home/vivek/backup /www-data

Where,

  • -T : Do not try to use TAR mode with Recursive mode

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 15 comments… read them below or add one }

1 haakondahl November 27, 2007

This is GREAT! I have been struggling with transferring files from multiple partitions on one machine to multiple partitions on another, so NFS doesn’t get it done no matter which isthe server of client. I am now using ProFTPd as a server, and ncftp as a client, and I am watching the partitions fill up as I expected, rather than as NFS and cp -vurf were getting it done.
Thank you for posting this fantastic guide!

Reply

2 Daniel August 26, 2008

Great. I’ve been trying to make a full copy of my ftp site for a backup.

Reply

3 Chris March 6, 2009

Thanks! needed to backup my site, and didn’t want to spend too much time writing a script…

Reply

4 nasser May 13, 2009

very nice guide.

I install ncftp client in CentOS and its work.

Reply

5 computerjan June 9, 2009

Very useful guide !
I´m using it for my FTP-Server

Reply

6 Ravi July 25, 2009

Hi Vivek,
Very nice and encourageing blog you have, it’s inspire to all of us, realy it works in all manner, I hope you could be feeling the same

Cheers
Go opensource……

Ravi Bhure

Reply

7 corky January 2, 2010

This is great…except where the directory on the ftp happens to have a [ or ] character in it. A file in a directory your getting can have those characters, just not the directory you specify in the command :(
ncftpget will return the error “remote directory listing failed.”

Really unfortunate, this was *almost* the perfect solution for me.

Reply

8 Daniel April 16, 2010

Seems like it dosn’t download all files, I just did this on one of my sites (-T command) and there where 3 directories that wasn’t downloaded.. had to download them one by one.. is there a limit to how many files/directories it will get?

Reply

9 daveX99 May 20, 2010

Hey – I was initially having trouble. Running the command as written, it would download any files in the remote directory, but not the subdirectories.

I had to add an asterisk to the line, so it looked like this (I ran it from the directory into which I wanted the files & directories to go):
$ ncftpget -R -v -u “username” http://ftp.remote_server.com ./ /Remote_Directory/*

Not sure why, but it did the trick.

-dave.

Reply

10 Anonymous May 20, 2010

Actually, I am also missing a few, but not all of the sub directories…

At this point, I’m now doing this by hand. Any ideas as to why this doesn’t work would be welcome.
-dave.

Reply

11 Brad Griffith July 8, 2010

A method that has worked much better for me is:

wget -r ftp://username:password@ftp.server.com/*

Reply

12 Karl November 12, 2010

Much better, quicker and easier method Brad, cheers!

Reply

13 k4m1 December 5, 2010

hehe wget rules again.
So clean and cool solution, thanks a lot :)
-q for quiet mode.

Reply

14 jbn June 17, 2011

Worked great. Except for it not doing recursion deep enough.

Currently trying
wget -m ftp://username:password@ftp.server.com/*
as it supposedly sets the correct options.

Reply

15 vamsi July 11, 2011

Thank You Solved my problem

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 8 + 3 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: