Quickly Backup a Site Through FTP with wget
If you want to quickly backup an entire website through FTP, the absolute easiest way to do this is through the command line using the wget command. In fact, you can backup an entire site (or whatever else is on the entire FTP server) with a single command string.
The syntax we’ll use is as follows:
wget -r ftp://username:password@domain.com/
Change the username and password to the appropriate login information, and change the domain to the site you wish to mirror/backup. If you’re curious, the -r flag just stands for recursive.
The entire website will be backed up locally in the directory the wget command was ran from, to prevent any potential clutter you may want to make a quick directory using mkdir and run wget from there, particularly if you’re working with very large web sites.
We’ve used wget to mirror a website locally before, it’s a powerful tool and is a worthwhile install if you’re an advanced user and don’t have it on your Mac already. Installing wget requires you to install something like XCode, HomeBrew, or MacPorts first, each of which also gives you access to thousands of other command line tools either through compiling source or prepackaged binaries.
I find the following useful.
wget -r -nH –cut-dirs=5 -nc ftp://user:pass@server//absolute/path/to/directory
Note the double slash after the server name. If I don’t put an extra slash the path is relative to the home directory of user.
-nH avoids the creation of a directory named after the server name
-nc avoids creating a new file if it already exists on the destination (it is just skipped)
–cut-dirs=5 allows me to take the content of /absolute/path/to/directory and to put it in the directory where I launch wget. The number 5 is used to filter out the 5 components of the path. The double slash means an extra component.
wget is nice, if you are not passing sensitive data.
# this command line is going to show your username and password in clear text
ftp://user:pass@server//absolute/path/to/directory
I think rsync (over ssh, i believe ssh is default nowadays) is a better utility if you need to authenticate your own credentials.
hey this is really handy I like it!
I find wget more reliable than a GUI client any day