Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to copy all of the files and folders from one host to another. The files on the old host sit at /var/www/html and I only have FTP access to that server, and I can't TAR all the files. Regular connection to the old host through FTP brings me to the /home/admin folder.

I tried running the following command form my new server:

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

But all I get is a made up index.html file.

What the right syntax for using wget recursively over FTP?

share|improve this question
Note that, by default, wget -r has a maximum recursion depth of 5; if you have an deeper subdirectories, they will be ignored unless you change this (see -l in the man page). –  mikewaters May 23 '11 at 19:21

12 Answers 12

Try -m for --mirror

wget -m ftp://username:password@ip.of.old.host
share|improve this answer
For security reason, it would be good to use --ask-password to avoid password being kept in history. –  checksum Oct 4 '14 at 2:49

You have it right, you just need a trailing * on the end:

wget -r ftp://username:password@*
share|improve this answer

You can use 'curlftpfs - mount a ftp host as a local directory' and, once mounted, you can use normal file tools like 'cp -r'.

share|improve this answer

besides wget, you may also use lftp in script mode. the following command will mirror the content of a given remote FTP directory into the given local directory, and can be put into the cron job:

lftp -c 'open <hostname>; user <username> <password>; mirror -e <remote-src-path> <local-dest-path>; quit'

it automatically handler recursion into directories and allows specifying the remote source starting directory from to download data from.

share|improve this answer

Should work try:

wget -r ftp://ftp:ftp@ftp.sunet.se/tst/
share|improve this answer

I can understand if you're trying to dump this into cron or something, but why not simply ftp into the server with your normal client and mget *? This might be a quicker path to success.

share|improve this answer
I tried mget * but it didn't work with sub-folders, saying the local sub-folder doesn't exist. Is there a way to make him create the local folders automatically? –  user9406 Jun 13 '09 at 17:16
Depending on your client, the -r switch usually does the trick. IE: mget -r * –  dr.pooter Jun 15 '09 at 6:17
mmm. AFAIK standard ftp client in linux is not designed to retrieve directories recursively. I mean - there is no -r option. other clients like ncftp or lftp support recursive retrieval but they usually not available by default. –  Stann Feb 13 '11 at 5:42

wget -m it will mirror all the files and folder

share|improve this answer
As I said, logging in through FTP takes me to the /home/admin folder, and the files I need are in /var/www/html So when I run the command you suggested, I only get the contents of /home/admin I tried running it with, but then it tries to CWD /home/admin/var/www/html. How do I make it go to this folder from the root? –  user9406 Jun 13 '09 at 17:23
I have no experience with this particular problem, but you could try making a symlink to /var/www/html under your home. Then you could use an address like –  prestomation Jun 13 '09 at 17:29
I tried creating a symlink, but it resulted with wget creating a similar symlink on my local. –  user9406 Jun 13 '09 at 17:32

That's the right syntax. Not sure why you aren't getting the expected results.

As ever there is more than one way to do it. Try ncftp, in particular ncftpget

share|improve this answer
I can't install more software on my new server. Shouldn't I be telling wget to download all files from /var/www/html? I tried wget -r username:password@ip.of.old.host/var/www/html but I got a directory not found error. –  user9406 Jun 13 '09 at 9:37

As I said, logging in through FTP takes me to the /home/admin folder, and the files I need are in /var/www/html

I think this will work in your case:

wget -r
share|improve this answer

Use -m rather than -r, because of the recursion depth.


share|improve this answer

I came across a windows hosting with the username as brinkster/username . so wget will throw an error if you use the syntax :

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

to get past this ,

wget -m ftp://brinkster%2Fusername:password@ip.of.old.host 

I had to face this with a windows hosting @ brinkster .

share|improve this answer

wget --user username --password yourpassword ftp://example.com/ftpfiles/filename will do the job or you can add * instead of filename entring : makes wget think of port which is invalid in your case.

share|improve this answer
This answer to a four year old question with multiple upvoted answers doesn't offer anything new and even omits the requirement for a recursive copy. –  Sven Jun 20 '13 at 0:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.