HexoFtpPublisher - 部署 Hexo 至指定 FTP 的協助發行工具

Introduction

雖然 Hexo 提供了 FTPSync 套件 hexo-deployer-ftpsync 讓使用者可以更簡單的將網站內容發布到指定的 FTP 上,但 hexo-deployer-ftpsync 無法刪除已存在的「數字名稱資料夾」導致部署時出錯(目標為 IIS FTP Server),因此決定直接 fork hexo-deployer-ftpsync 修改這個問題。

開玩笑的,我不會 Node.js,對 JavaScript 也不是非常熟悉,因此這個程式是基於 .NET Core 2.1 所建構的,不然文章就不用多 .NET CoreC# 的 Tag 了。

HexoFtpPublisher

基於 .NET Core 2.1 與 FluentFTP,部署 Hexo 至指定 FTP 的協助發行工具。

Supports

在安裝完成後請首先檢查 Runtime 是否安裝成功

1
$ dotnet --version

檔案下載

HexoFtpPublisher-binary-1.0.0.0.zip

檔案結構

1
2
3
─┬─ HexoFtpPublisher.dll
├─ HexoFtpPublisher.runtimeconfig.json
└─ FluentFTP.dll

參數說明

Parameter Desciption Required Options Default Value
–host FTP Host yes
–port FTP Port 21
–user Login Username (Anonymous)
–pass Login Password
–source Source Folder .\public
–remote Remote Folder yes
–clean_remote Clean Remote Folder Content yes/no (or y/n) yes
–exist_action The Action If File Exist append/overwrite/skip overwrite
  • exist_action
    • append
      若檔案存在,透過檢查檔案長度並添加缺少的資料於檔案上。(Append to the file if it exists, by checking the length and adding the missing data.)
    • overwrite
      若檔案存在,覆蓋檔案。(Overwrite the file if it exists.)
    • skip
      若檔案存在,則跳過該檔案並不再進行任何檢查。(Skip the file if it exists, without any more checks.)

使用範例

以匿名使用者登入

1
$ dotnet HexoFtpPublisher.dll --host 127.0.0.1 --remote "/blog"

清除目標資料夾內容後上傳指定資料夾內容

1
$ dotnet HexoFtpPublisher.dll --host 127.0.0.1 --user USERNAME --pass PASSWORD --source "..\..\..\public" --remote "/blog"

不清除目標資料夾內容並以新增模式上傳檔案

1
$ dotnet HexoFtpPublisher.dll --host 127.0.0.1 --user USERNAME --pass PASSWORD --source "..\..\..\public" --remote "/blog" --clean_remote no --exist_action append

直接執行程式並依序輸入參數

1
2
3
4
5
6
7
8
9
$ dotnet HexoFtpPublisher.dll
Host:
Port:
User:
Pass:
Source Folder:
Remote Folder:
Clean Remote Path (Y/n):
Exist File Option (append/overwirte/skip):

Remark

使用者可以預先定義好 HexoFtpPublisher 參數並儲存成腳本(*.bat、*.sh),之後便只需要一行指令完成遠端部署。

For Example

以 Windows 系統為例,先建立一 bat 檔案:

1
$ dotnet HexoFtpPublisher.dll --host 127.0.0.1 --user USERNAME --pass PASSWORD --source "..\..\..\public" --remote "/blog"

之後部署的流程就可以變成

1
2
3
$ hexo clean
$ hexo generate
$ publish.bat

References