files synchronization with ftp

Multiple hosts synchronization with NCFTP

Sometimes we need the same source code on multiple servers. It could be done with rsync, but mostly we don’t have a ssh access. However we can still use FTP to do it for us.

NCFTP

In linux systems, like Ubuntu we can use ncftp. To install it type:

sudo apt-get update
sudo apt-get install ncftp

From now on you can use it to copy your local files to the remote ftp account.

ncftpput -v -R -u "ftpuser" -p "ftppassword" REMOTE_FTP_HOST /your/ftp/path/ /your/local/direct/path/*

That works fine, but the title says “multiple”. If we have more then one host which needs to be synchronized, we can use Bash Scripting. Let’s create a new executable file.

touch ftpsynch.sh
chmod +x ftpsynch.sh
vi ftpsynch.sh

Then add as many lines as needed.

#!/bin/bash

echo 'sending REMOTE_FTP_HOST#1'
ncftpput -v -R -u "ftpuser1" -p "ftppassword1" REMOTE_FTP_HOST#1 /your/ftp/path/ /your/local/direct/path/*

echo 'sending REMOTE_FTP_HOST#2'
ncftpput -v -R -u "ftpuser2" -p "ftppassword2" REMOTE_FTP_HOST#2 /your/ftp2/path/ /your/local/direct/path/*

# ...

When ready, hit ESCAPE and double SHIFT+Z to save the file and run it.

./ftpsynch.sh

You’ll see a list of files being sent to your ftp hosts. It may take some time depending on the amount and size of files.
Use it well nerds.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>