up vote 20 down vote favorite
6
share [g+] share [fb]

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?

link|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). – threecheeseopera May 23 '11 at 19:21
feedback

9 Answers

Try -m for --mirror

wget -m ftp://username:password@ip.of.old.host
link|improve this answer
feedback

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

wget -r ftp://username:password@1.2.3.4/dir/*

Cheers

Richard

link|improve this answer
feedback

Should work try:

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

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.

link|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
feedback

wget -m ftp://192.168.0.1 it will mirror all the files and folder

link|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 192.168.0.1/var/www/html, 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 192.168.0.1/html – 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
feedback

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

link|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
feedback

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.

link|improve this answer
feedback

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

link|improve this answer
feedback

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 ftp://192.168.0.1/../../var/www/html
link|improve this answer
feedback

Your Answer

 
or
required, but never shown