# SFTP同期

## 概説

Keeperボルトに保存されたクレデンシャルを使用することで、FTPサーバーへの接続が容易になり、Commanderはサーバーからマシン上の指定した場所にファイルを自動的にダウンロードできるようになります。

Commanderを使用してSFTPのクレデンシャルの保護するか、ファイルのダウンロードやバックアップを自動化します。

## ファイルを同期

CommanderのSFTP同期を使用するには、`rsync`コマンドを使用します。

### 初回設定

SFTP同期を初めて実行するときは、プラグインのタイプ、リモートファイルへのパス、使用するクレデンシャルの記録を指定する必要があります。

`--plugin` 使用するプラグインの種類 (SFTPを使用)

`--remote-path` SFTPディレクトリにダウンロードするファイルへのパス

`--record` UIDまたはSFTPのクレデンシャルを格納する記録へのパス

例:

{% code overflow="wrap" %}

```bash
rsync "path/to/files_location/" --plugin sftp --remote-path "/path/to/files" --record "credentials/SFTP creds"
```

{% endcode %}

これらのオプションを一度指定すると、Commanderは指定した記録に対してオプションを保存するので、以降のSFTP同期はファイルのダウンロード先を指定するだけで実行できます。

```bash
rsync "path/to/files_location/"
```

## 同期の自動化

Commanderは複数の方法で自動化できます。詳細は、[バッチモードのドキュメント](/keeperpam/jp/commander-cli/commander-installation-setup/logging-in.md#executing-commands-with-persistent-login)をご参照ください。このセクションでは、SFTP同期の自動化の例について説明します。

### SFTP同期を繰り返し実行

Commanderは、Commander設定ファイルを編集することによって、特定の頻度でコマンドを実行するように設定できます。

SFTP同期の初期設定を実行した後、特定の頻度で同期するようにCommanderを設定できます。

Commanderを自動化して、24時間に1回SFTPサーバーと同期させるには、以下のフィールドを設定に追加します。

`"commands": ["rsync"],`

`"timedelay":86400`

完全な設定ファイルの例:

{% code title="sync.conf" %}

```
{
    "server": "keepersecurity.eu",
    "user": "services@company.com",
    "private_key": "yaeK4jMeIGNkSR2[...]AA",
    "device_token": "g6RDMxr[...]z-xQ",
    "commands": ["rsync"],
    "timedelay":86400
}
```

{% endcode %}

設定の完了後、編集した設定ファイルを使用してCommanderを実行し、自動化を開始します。コマンドライン/ターミナルから実行できます。

`$> keeper shell --config "/sync.conf"`

{% hint style="info" %}
設定ファイルにはその他のフィールドがある場合があります。詳細については、[こちら](/keeperpam/jp/commander-cli/commander-installation-setup/configuration/configuration.md#commander-configuration-file)をご参照ください。

Commanderは実行し続けながら、次のコマンド実行を待ちます。Commanderを終了した場合やマシンの電源を切った場合に続行するには、Commanderを再起動する必要があります。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/commander-cli/command-reference/connection-commands/sftp-sync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
