The other day I was tasked with mirroring a FTP site, about 5+ gigs of files, on our local server. Mirroring directories is a fairly common task when administering servers, however, the main differences when tasked with this job are the protocols available, whether the job is bi-directional or one way, and the how fast the mirroring needs to occur.
Lucky for me, this job did not demand instantaneous sync and the job was only one way – meaning changes from a server were reflected only from one server. The biggest problem was this job was limited to using only the FTP protocol for mirroring the site. This immediately removed rsync, a popular server/client for syncing directories remotely, as an option. After a quick search through the Ubuntu forums, I stumbled upon a post that detailed several programs on mirroring an FTP site using FTP protocol only. I chose a program called ‘ftpmirror’.
Ftpmirror is a program that lets a user define ‘packages’, which are configuration details for mirroring an FTP site, and scheduling these ‘packages’ to be run daily, monthly, or weekly. To install this program, I typed
sudo apt-get install ftpmirror
If you’re using Ubuntu Server, the configuration files should reside in the ‘/etc/ftpmirror/’ directory. Upon browsing through the directory, you will find a file called ‘ftpmirror.cf-sample’. This file contains a few example ‘packages’ that can be used as a template. The user puts any active ‘packages’ in the ‘ftpmirror.cf’ file. My ‘ftpmirror.cf’ file looks like this:
package = alexkuo_media
ftp-server = master.alexkuo.info
ftp-user = mirror
ftp-pass = password
remote-directory = /media/pics/
local-directory = /home/deploy/media/pics
This package uses the directory ‘/media/pics/’ as the root directory on the ftp server ‘master.alexkuo.info’ and uses the login/password, mirror/password, to login into the remote server. All files, directories, and subdirectories found in the ‘/media/pics’ directory are then downloaded into the ‘/home/deploy/media/pics’ directory on the local machine once the package is activated.
I decided to run this job once a week, so I added the package to the ‘/etc/ftpmirror/list.weekly’ file. To do this, open the ‘list.weekly’ file with a text editor. Mine looks like this:
Pretty plain huh? I removed the comments that originally came with the file, so it looks pretty bare. Adding another package involves defining another package in the ftpmirror.cf file and appending the package name on a new line in one of the *.list files.