Table of Contents
If you have a small Hugo static site and your hosting provider just offers FTP access and not SSH/rsync, synchronizing the site manually can be difficult. With access to your web host via FTP, you can use sitecopy1 to incrementally deploy your entire Hugo site, similar to rsync solution.
sitecopy is a tool for copying locally stored web sites to remote web servers. A single command will upload files to the server which have changed locally, and delete files from the server which have been removed locally, to keep the remote site synchronized with the local site. The aim is to remove the hassle of uploading and deleting individual files using an FTP client. sitecopy will also optionally try to spot files you move locally, and move them remotely.
- Access to your web host with FTP
- A functional static website built with Hugo
sitecopy is available in all major distributions, so just use your favourite package manager to install it:
sudo apt-get -y install sitecopy
Optionally, you should take a quick look at sitecopy‘s man page to familiarize yourself with its options:
In your home folder create the directory
.sitecopy (with permissions
700) – sitecopy uses this directory to store synced files details. After that, we will need to create the sitecopy configuration file
Open .sitecopyrc file in your editor and fill in the configuration for the
The state checksum configuration is important here. Since Hugo does not support incremental builds, all the files in the public folder will be regenerated when you rebuild your Hugo site. By using checksum method for the sitecopy state (and not the default timesize) we make sure that only the files that are truly modified will be synchronized.
Most of the configuration options are self-explanatory. The site directive must be followed by a name for the web site – you can freely choose one, e.g.
ftp.mysite.com – this name will be used later on with the sitecopy commands. The local directive contains the local path of the web site – in this case, Hugo's public folder, remote contains the path of the web site on the remote server – it can be absolute or relative.
The exclude lines are optional, they allow you to exclude files and folders (last 2 exclude lines) from being synchronised with sitecopy.
Initialising the site
For this example we will use the most common scenario, where the local copy exists – your Hugo site – and you have an empty remote site.
There are other scenarios that might fit your situation for witch you will need to consult the sitecopy man page and modify the script accordingly.
First initialise the site (replace hugosite.com with the name of the site you use in the .sitecopyrc file):
Then, upload the local copy to the remote site using
sitecopy --update hugosite.com:
sitecopy will MD5 checksum every file from your public Hugo folder and store the information in the
~/.sitecopy/[sitename] file. Here is a excerpt from the
~/.sitecopy/hugosite.com file generated by the command above:
Next time when you will build your Hugo site and run
sitecopy --update , sitecopy will check the MD5 checksum of the files and update them accordingly.
Using Hugo and sitecopy
Hugo FTP sync via sitecopy usage is really easy. Modify your Hugo site as needed and when done build it again, e.g.:
hugo --minify --cleanDestinationDir --gc.
Next, an optional step is to run
sitecopy hugosite.com to find out which files have changed locally (replace hugosite.com with the name of the site you use in the .sitecopyrc file):
To synchronize your local Hugo site – upload new and changed files to the remote server and delete files on the remote server that have been deleted locally – you simply run
sitecopy --update hugosite.com:
For your convenience, you can find most of above in the shell script below. For this script to work, you need to initialise the site first, as described above.
The script accepts two parameters:
check(default, optional) – to check and display the current changes. Running the script with this option (or without any option) will check the changes in the local site (via the ~/.sitecopy/[sitename] file), put them in a HTML file (see the –flatlist option in man page) and display them via lynx4 browser.
./ftp-sync.sh check # or ./ftp-sync.sh
sync– to perform the actual synchronisation if there are any changes available:
Feel free to adapt it to suit your needs and happy Hugo!