# Archive Files to SFTP Server

Cloud Voice can copy your call recordings and system backups to an external SFTP (SSH File Transfer Protocol) server, either automatically on a recurring schedule or as a one-off transfer whenever you need it. SFTP is a secure, encrypted way to move files between machines. To set this up, you first register the SFTP server as an archive destination, then create one or more tasks that decide which files move, how often, and how they are stored. This page covers both steps.

## Requirements

- **Firmware**: Version 84.22.0.17 or later.
- **Plan**: Enterprise Plan (self-managed phone system) or Ultimate Plan (hosted phone system).

## Limits

- You can register up to **10** archive servers.
- You can create up to **200** archive tasks.

## Before you start

Have the following ready:

- An SFTP server, along with its **Domain/IP Address** and **Port**.
- An SFTP account that has both read and write permission, along with its **Username** and **Password** or **Private Key**.

:::note
If you plan to have Cloud Voice remove old files from the SFTP server automatically, the account also needs permission to delete files.
:::

## Step 1: Register the SFTP server as an archive destination

1. Sign in to the web portal and go to **System > Archive**.
2. On the **Archive Task** tab, click **Archive Server**.

   ![The Archive Server button on the Archive Task tab](/images/pbx/click-archive-server.png)
3. Add the SFTP server:
   1. Click **Add**.
   2. In the dialog that opens, fill in the following fields:

      ![Dialog for entering SFTP archive server connection details](/images/pbx/sftp-archive-server-setting.png)

      - **Name**: A label that helps you recognize this server.
      - **Server Type**: Select **SFTP**.
      - **FTP Server Domain/IP**: The address of your SFTP server.
      - **Port**: The port your SFTP server listens on. The default is `22`.
      - **Username**: The username of the SFTP account.
      - **Authentication Method**: Choose how to authenticate, then enter the matching credential.
   3. Click **Save**. The server now appears in the archive server list.
4. Click the close icon ![Close](/images/pbx/close-window.png) to dismiss the window.

## Step 2: Create an archive task

1. On the **Archive Task** tab, click **Add**.
2. Under **Task Configuration**, set the basics for the task:

   ![Task configuration fields for a new archive task](/images/pbx/s3-archive-task.png)

   - **Name**: A label that helps you recognize this task.
   - **File Type**: Select **Recording Files** or **Backup Files**.
   - **Data Range**: The time span of files to include.

     :::note
     A single task can cover a range of up to 31 days.
     :::
   - **Sync Frequency**: How often the task runs.
     - **Once**: Archives the files as soon as you save the task.
     - **Daily**: Pick a time of day; the task runs at that time every day.
     - **Weekly**: Pick a day of the week and a time; the task runs then each week.
     - **Monthly**: Pick a day of the month and a time; the task runs then each month.

     :::caution
     Moving large volumes of data uses the phone system's CPU (processor) resources, so schedule recurring tasks for off-peak hours.
     :::
   - **Recording File Format**: The download format for recording files. This applies to every recording file in the system, and the option appears only when the file type is set to recording files.
3. Under **Storage Configuration**, choose where and how the files are stored:
   - **Archive Server**: Select the SFTP server you registered in Step 1.
   - **Select Folder/Path**: Optional. The folder on the server where files are stored, for example `pbx/backup/`. Leave it blank to store files in the root directory.
   - **Storage Method**: How files are laid out on the server. The available choices depend on whether the task runs once or on a recurring schedule.
     - For a one-time task:
       - **Create Task Folder**: Creates a folder named `FileType-TaskName` under the path and stores the files inside it.
       - **Save Directly to Selected Path**: Stores the files straight in the path, with no extra folder.
     - For a recurring task:
       - **Create Folder per Execution**: Each run creates a folder named `FileType-TaskName-ExecutionDate` under the path and stores that run's files inside it.
       - **Create Task Folder Once and Reuse It**: The first run creates a folder named `FileType-TaskName`, and every later run stores its files in that same folder.
       - **Save Directly to Selected Path**: Every run stores its files straight in the path, with no extra folder.
   - **Skip archived files**: Optional, and shown only for recording files. When enabled, files that were already archived are skipped. When disabled, they are archived again: the stored location is updated, but the earlier copy is left in place on the third-party server.
   - **Delete local files after archiving**: Optional, and shown only for recording files. When enabled, recordings are removed from local storage once archived. They can still be played and downloaded from the admin portal and the Cloud Voice App, but are no longer available for playback or download on the third-party server or Dynamics 365. When disabled, local copies are kept.
   - **Organize Files by Date**: Optional. When enabled, the task creates date-based subfolders named in `YYYYMMDD` format (for example, `20260301`) under the storage path. When disabled, files go straight into the path with no date grouping.

     :::note
     If the selected data range contains only one record, no date subfolder is created and the file is stored directly in the path.
     :::
4. Optional. Set a retention policy so old archives are cleaned up automatically.

   :::note
   - Retention is available only for recurring tasks.
   - The SFTP account must have permission to delete files on the server.
   :::

   ![Retention policy settings for an archive task](/images/pbx/archive-retention-settings.png)

   - **Retention Type**:
     - **Retention by Quantity**: Keeps a maximum number of files or folders. Enter the number in **Retention Limit (files/folders)**. When the count is exceeded, the oldest items are deleted automatically.
     - **Retention by Days**: Keeps items for a maximum period. Enter the number of days in **Retention Limit (in days)**. Items older than the limit are deleted automatically.

       :::note
       - The period is counted from the time a file is archived on the server, not from when it was created on the phone system.
       - Days are measured as exact 24-hour intervals, not calendar days.
       :::
   - **Retention Limit**: The maximum number of files or folders, or the maximum number of days, depending on the retention type.
   - **Retention Unit**:
     - **Folder**: Counts the task folders created on the server. This is available only when the storage method is **Create Folder per Execution**, and it excludes any date subfolders created by **Organize Files by Date**.
     - **File**: Counts the individual files on the server.
5. Click **Save**.

## Result

The selected files are copied to the folder you specified on the SFTP server, either right away or at the scheduled time.

:::note
To protect performance, the system runs one task at a time. When several tasks are due, they run one after another in a queue.
:::

You can confirm the outcome in two ways:

- **In the web portal**: Go to **System > Archive > Archival Logs**. When the **Result** column shows **Succeeded**, the files reached the SFTP server.

  ![Archival Logs listing task results](/images/pbx/archival-logs.png)

  :::note
  A failed task triggers the **Failed to Archive File(s)** event. Click the retry icon ![Retry](/images/pbx/Restore.png) to run the task again.

  ![Retrying a failed task from the archival logs](/images/pbx/retry-archive-task.png)
  :::
- **On the SFTP server**: Open the target folder. If the files are listed there, the archive succeeded.

  ![Archived recording files listed on the SFTP server](/images/pbx/recording-file-on-ftp.png)
