> ## Documentation Index
> Fetch the complete documentation index at: https://developer.dromo.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Scheduled SFTP Imports

> Set up Dromo to pull files from your SFTP server on a schedule and run each one as a headless import against a saved schema.

With scheduled SFTP imports, Dromo connects to your SFTP server on a schedule, picks up the files in a folder you choose, and runs each one as a [headless import](https://developer.dromo.io/getting-started/headless.md) against a saved schema. Nobody needs to upload anything.

## Prerequisites

* **Headless enabled for your organization.** SFTP imports are part of Headless, a premium add-on to the [Dromo Enterprise Plan](https://dromo.io/pricing). [Get in touch](mailto:support@dromo.io) to have it turned on.
* **A saved schema.** Every connector imports into one saved schema. Create it in [Schema Studio](https://developer.dromo.io/guides/schema-builder.md) or with the [Saved Schema API](https://developer.dromo.io/guides/saved-schema-api.md).
* **An SFTP user that Dromo can sign in as**, with permission to list, read and delete files in the folder. Dromo deletes each file from your server once it has picked it up, so use a folder that holds only files meant for Dromo.
* **A backend license key**, if you are setting up through the API. See [Authentication](https://developer.dromo.io/api-reference/authentication.md).

You can do every step below in the Dromo dashboard, on the **Headless** page, or through the API. The examples use the API.

## Setting up

**1. Create credentials**

Credentials tell Dromo how to sign in to your server. Use the [create SFTP credentials endpoint](https://developer.dromo.io/api-reference/sftp-credentials/create-sftp-credentials.md).

```sh theme={null}
curl \
  -H "Content-Type: application/json" \
  -H "X-Dromo-License-Key: your-backend-key" \
  -X POST 'https://app.dromo.io/api/v1/headless/sftp/credentials/' \
  -d '{
    "hostname": "sftp.example.com",
    "port": 22,
    "user": "dromo",
    "auth_type": "PASSWORD",
    "password": "your-sftp-password"
  }'
```

Set `auth_type` to `"PASSWORD"` and send `password`, or to `"KEY"` and send `private_key`. A private key must be in OpenSSH format and must not have a passphrase.

Passwords and private keys are stored encrypted and are never returned by the API. For key authentication, the response includes a `key_fingerprint` so you can confirm which key is in use.

The response includes the credentials `id`, which you need for the next two steps.

**2. Test the connection**

Check that Dromo can reach your server with the [test SFTP connection endpoint](https://developer.dromo.io/api-reference/sftp-credentials/test-sftp-connection.md).

```sh theme={null}
curl \
  -H "X-Dromo-License-Key: your-backend-key" \
  -X POST 'https://app.dromo.io/api/v1/headless/sftp/credentials/{id}/test_connection/'
```

Dromo signs in and lists the home folder. The response is `{ "success": true }`, or `{ "success": false, "error": "..." }` with the reason. If the connection times out, check that your firewall allows connections from Dromo.

**3. Create a connector**

A connector ties together the credentials, a folder, a saved schema and a schedule. Use the [create SFTP connector endpoint](https://developer.dromo.io/api-reference/sftp-connectors/create-sftp-connector.md).

```sh theme={null}
curl \
  -H "Content-Type: application/json" \
  -H "X-Dromo-License-Key: your-backend-key" \
  -X POST 'https://app.dromo.io/api/v1/headless/sftp/connectors/' \
  -d '{
    "credentials": "ee5d0e45-b098-47bc-8217-e93790243dfa",
    "schema": "4eefe3fe-7181-4562-aa28-8cfe1c5bdf1b",
    "directory": "/uploads",
    "file_regex": ".*\\.csv$",
    "schedule": { "type": "every_n_minutes", "minutes": 15 }
  }'
```

**credentials** `string` *required*

The ID of the credentials to sign in with.

**schema** `string` *required*

The ID of the saved schema each file is imported into.

**directory** `string` *required*

The folder on your server to pick files up from.

**file\_regex** `string | null`

A regular expression that file names must match to be picked up. Leave it out to pick up every file in the folder. See [how files are picked up](#how-files-are-picked-up).

**schedule** `object` *required*

When Dromo checks the folder. See [schedule options](#schedule-options).

## Schedule options

A connector runs on one of two kinds of schedule:

| Schedule | Example | Notes |
| - | - | - |
| Every N minutes | `{ "type": "every_n_minutes", "minutes": 15 }` | The minimum is 5 minutes. |
| Daily at a set time | `{ "type": "daily_at_time", "time_utc": "09:00" }` | 24-hour `HH:MM`, in UTC. |

## How files are picked up

Each time the schedule fires, Dromo signs in, opens the connector's `directory` and looks at the files directly inside it. Subfolders are not searched.

* If the connector has a `file_regex`, only files whose names match it are picked up. The pattern is a regular expression, not a glob, and it is matched from the start of the file name. Use `.*\.csv$` for every CSV file, not `*.csv`.
* Every matching file in the folder is picked up, each as its own import.
* Dromo copies the file and then **deletes it from your server**. It does not move or archive it. A file left in the folder would be imported again on the next run, so the delete is how Dromo knows a file is done. Keep your own copy if you need one.

> [!WARNING]
>
> Upload files to a temporary name or folder and rename or move them into the pickup folder once they are complete. A file that is still being written when the schedule fires can be picked up half-finished.

## What happens after pickup

Dromo creates one headless import for each file, using the connector's saved schema as it is at that moment and the file's name as the import's filename. From there it is an ordinary headless import: it runs the schema's validations and [hooks](https://developer.dromo.io/reference/hooks.md#hooks-in-headless-imports), and finishes as `SUCCESSFUL`, `NEEDS_REVIEW` or `FAILED`. See [handling import results](https://developer.dromo.io/getting-started/headless.md#handling-import-results) for what each status means.

Imports from SFTP always run in production mode and count towards your usage.

## Where results go

Nothing is written back to your SFTP server. You get the results the same way as for any headless import:

* **Webhooks (recommended).** Set up a [webhook](https://developer.dromo.io/reference/webhooks.md) for the connector's saved schema in the dashboard. Dromo sends `import_completed` when an import succeeds, `headless_import_needs_review` when it needs a person to fix something, and `headless_import_failed` when it cannot be processed. Each one carries the import's ID.
* **The Headless API.** [List headless imports](https://developer.dromo.io/api-reference/headless/list-headless-imports.md) to find the imports a connector created, then [retrieve one](https://developer.dromo.io/api-reference/headless/retrieve-headless-import.md) for its status and review URL, and [get its download URL](https://developer.dromo.io/api-reference/headless/get-presigned-download-url-for-headless-import-data.md) for the cleaned data.
* **The dashboard.** The **Headless** page lists each import with its status.

## When a connector fails

If a run cannot connect or cannot read the folder, Dromo tries again on the next scheduled run. After 5 failed runs in a row, Dromo turns the connector off and emails your organization's admins. Fix the cause, [test the connection](https://developer.dromo.io/api-reference/sftp-credentials/test-sftp-connection.md), then turn the connector back on in the dashboard.

## Changing or removing a connector

Update credentials and connectors with a `PUT` request to the [update SFTP credentials](https://developer.dromo.io/api-reference/sftp-credentials/update-sftp-credentials.md) and [update SFTP connector](https://developer.dromo.io/api-reference/sftp-connectors/update-sftp-connector.md) endpoints. When updating credentials, leave out `password` or `private_key` to keep the one already stored.

Deleting a connector stops its schedule. Imports it has already created are not affected.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.