BG1REN's BLOG

Technology, Life, and Infinite Possibilities...


Hugo+rsync+lftp Website Publishing

Normally, when Hugo generates a static website, timestamps of many files change even if their content remains identical.

This makes incremental updates inefficient when using FTP tools that rely on file timestamps for differential synchronization.

We can solve this using rsync.

Create an ftp-public directory as a local mirror of Hugo’s output public directory. This divides website publishing into two steps:

  1. Use rsync to synchronize changes to the ftp-public directory. This step compares file content differences, only updating changed files while preserving timestamps of unchanged files.
  2. Use lftp to synchronize the ftp-public directory to the website’s FTP server.

Here are the specific commands:

rsync -rv --delete --checksum --progress public/ ftp-public/

Explanation of rsync options:

  • -r Recursively sync subdirectories
  • -v Verbose output
  • --delete Remove files/directories from ftp-public/ that don’t exist in public/
  • --checksum Use checksums to determine file differences and update needs
  • --progress Show synchronization progress
lftp -e "mirror -R --delete --only-newer ftp-public/ /" ftp://ftpuser@ftpserver