Monthly Archives: November 2007

using wget to replicate a shared ftp folder

I was looking for a simple way to replicate a shared ftp folder to another machine. The replication must be done periodically via cron and it must have a way to resume in case it was interrupted.

The shared folder has the following characteristics:

  • user authentication is required when copying
  • files when uploaded are not changed/updated
  • filenames are unique and may have a directory structure

The above-mentioned requirements are simple so I though maybe I can use wget for this, it has a resume option and it also has an optional authentication method… so maybe it can work.

After some series of trials and errors, I got it working… here’s the code snippet:

#!/bin/bash

user=’ftp user name here’
pass=’ftp password here’

wget –timeout=30 -nH -qrc –level=20 –user=”$user” –password=”$pass” \
ftp://host.here/dir_to_copy/ –directory-prefix=”$HOME”

rsync may have a better approach, but this one worked for me and I’m quite lazy, so why bother…