Zeke Xiao

Zeke Xiao

github

Sync hugo to ftp using git-ftp

Introduction#

Git-ftp is an ftp application that uses git as version control. It can upload only the files that need to be updated based on git changes, saving bandwidth and time.

Installation#

For Debian-based systems, simply install:

sudo apt install git-ftp

For other versions, you can find specific instructions here. Simply extract and run.

Usage#

Adding Config#

You can directly add the following to the .git/config file of your git project:

[git-ftp]
    url = ftp.example.net
    user = ftp-user
    password = secr3t

Alternatively, you can use git commands to add the config:

git config git-ftp.url ftp.example.net
git config git-ftp.user ftp-user
git config git-ftp.password secr3t

Specific Config Parameters#

git config git-ftp.url ftp://ftp.example.net:8010/path ftp address

git config git-ftp.user ftp-user ftp username

git config git-ftp.password secr3t ftp password

git config git-ftp.syncroot path/dir local directory to sync

git config git-ftp.remote-root htdocs remote directory

For more information, refer to the manual

Syncing#

Initialize syncing for all files

git ftp init

Other usage is simple. Simply commit files within git and then use

git ftp push

to sync to the remote directory. A .git-ftp.log file will be created in the ftp to record commit versions of files in the ftp. By comparing with the local git, only the updated parts will be uploaded.

Syncing with Hugo#

Originally, the blog was synced using Caddy + git + hugo. However, it was a bit wasteful to only run this program on the VPS. Luckily, Baidu Cloud's virtual host was on sale for only 30 yuan per year, so I moved it to the virtual host.

To sync, follow the instructions above to add the ftp configuration. Then, remove the ./public directory from the .gitignore file. The git-ftp.syncroot path should be $PATH_TO_YOUR_HUGO/public. After generating the files in the public directory using hugo -E and committing the changes, use git ftp push to sync.


Switched to typlog in September 2019
Switched to xlog.app in July 2023

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.