Recently I was discussing with someone the need to simplify the sync of a folder into an FTP server. The goal is that at set intervals, any change in a remote server is pulled to q local folder: changes changed, new files created, removed files removed. This is that kind of thing that should be easier, but it’s mixing an old technology (rsync) with a very, very old technology (FTP).
This is how to do it using mount_ftp and rsync.
The general idea is to use the mount_ftp
almost like FUSE-mounting a remote resource, then using rsync
on that mounted filesystem. If we wrap it around mktemp
to work relatively portably in a temp folder, we’d have something like this:
- local folder: ${HOME}/contrib
- remote server: ftp.example.com
- remote folder: ./Scott/ABC
- remote user: scott
- remote pass: tiger
# create a temporary/random mountpoint TEMPFILE=$(mktemp -d -t ftprsync) # mount the remote space; no output, but the return code matches errno.h values sudo mount_ftp -o rw ftp://scott:tiger@ftp.example.com/Scott/ABC ${TEMPFILE} ; echo $? # sadly, despite best efforts (and "-o rw"), this is only a read-only, so only good # for syncing FTP content out to the local system # sync rsync -avr --delete-after ${TEMPFILE}/* ${HOME}/contrib #shut it down sudo umount ${TEMPFILE} rm -fr ${TEMPFILE}
Recent Comments