Class SftpSshClientFactory

java.lang.Object
io.leandev.appfuse.file.sftp.SftpSshClientFactory

public final class SftpSshClientFactory extends Object

建立供檔案儲存、交易 journal 與暫存清理共用的 SSH client。

預設只使用呼叫端明確提供的連線設定與認證,不讀取個人的 ~/.ssh/config 或預設私鑰。主機金鑰驗證獨立於認證設定,必須由應用提供 ServerKeyVerifier(例如明確指定 known_hosts 路徑或固定伺服器公鑰)。

回傳的 client 尚未啟動;應用負責 start()/stop(),並將同一實例傳給 SftpFileStorage、SftpFileJournal 與 SftpStagingCleanupTask 的 builder。 明確指定的 privateKeyPath/privateKeyPassphrase 仍由各元件正常載入。

Feature 的 FileStorageConfig 可將既有的主機金鑰驗證器接入共用 bean:

@Bean(initMethod = "start", destroyMethod = "stop")
public SshClient sshClient(ServerKeyVerifier serverKeyVerifier) {
    return SftpSshClientFactory.create(serverKeyVerifier);
}

應用升級到包含本 factory 的框架版本後,再以此取代自行建立 client 的程式碼。

  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.sshd.client.SshClient
    create(org.apache.sshd.client.keyverifier.ServerKeyVerifier serverKeyVerifier)
    建立隔離個人 SSH 設定的 client,保留呼叫端指定的主機金鑰驗證。
    static org.apache.sshd.client.SshClient
    createWithUserConfiguration(org.apache.sshd.client.keyverifier.ServerKeyVerifier serverKeyVerifier)
    明確 opt-in Apache MINA SSHD 的個人 SSH 設定與預設私鑰探索。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static org.apache.sshd.client.SshClient create(org.apache.sshd.client.keyverifier.ServerKeyVerifier serverKeyVerifier)
      建立隔離個人 SSH 設定的 client,保留呼叫端指定的主機金鑰驗證。
      Parameters:
      serverKeyVerifier - 必填的伺服器主機金鑰驗證器
      Returns:
      尚未啟動的 client
    • createWithUserConfiguration

      public static org.apache.sshd.client.SshClient createWithUserConfiguration(org.apache.sshd.client.keyverifier.ServerKeyVerifier serverKeyVerifier)

      明確 opt-in Apache MINA SSHD 的個人 SSH 設定與預設私鑰探索。

      個人設定可能影響連線目的地及認證;無法載入的個人私鑰也可能使認證失敗。 此選項不變更呼叫端指定的主機金鑰驗證政策。

      Parameters:
      serverKeyVerifier - 必填的伺服器主機金鑰驗證器
      Returns:
      尚未啟動的 client