# SFTP

Have each new build of VPNDetection's databases uploaded to your own server over SFTP, signing in with a key made for the destination, or over FTPS.

VPNDetection uploads each new build of the databases you choose to a server of yours, over SFTP or over FTP with TLS. What lands there, and when, is on [Database Delivery](/integrations/database-delivery#what-a-storage-destination-receives). Each file goes up under a temporary name ending in `.partial` and is renamed once it's complete, so nothing reads half a file.

Use SFTP where your server offers it. VPNDetection signs in with an SSH key it makes for the destination, so no password changes hands, and it pins your server's host key at the first test. Use FTPS for a server that speaks FTP: delivery uses it over TLS alone, never plain FTP.

## Before you begin

- The **Manage database delivery** permission in your organization, which owners and admins have.
- A license for at least one database. Every organization holds the Open databases from the start.
- A server that accepts connections from the internet on its SFTP or FTPS port. Deliveries don't come from a fixed set of addresses, so a server that only takes connections from listed ones won't accept them.
- A user for the delivery, with write access to the folder: for SFTP, access to that user's `~/.ssh/authorized_keys`, and for FTPS, its password.

## Set up SFTP

### 1. Add the destination

In the [console](https://app.vpndetection.io/database/delivery), under **Database** > **Delivery**, click **Add destination** and pick **SFTP**.

### 2. Enter the server

Under **Connection**, enter the server's **Host** and **Port**, the **Username** VPNDetection signs in as, and a **Folder**. A folder starting with `/` is absolute, and anything else is under the user's home.

### 3. Authorize the destination's key

VPNDetection signs in with an SSH key it makes for the destination, which is what it recommends. Leave **Our SSH key (recommended)** selected and click **Save**, and the destination shows its public key, one line to add to that user's `~/.ssh/authorized_keys`:

```text
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGs1d0RkE5Ge2Jw0n3qM8wq1q5c0V3Gm5n7Jk2bq8pZx vpndetection-delivery
```

The private half never leaves VPNDetection, and deleting the destination is the end of it. A password works too, where the server takes one: choose **Password** instead, and enter it.

VPNDetection needs the SFTP protocol alone, never a shell, so a chrooted SFTP-only user works, as do managed servers such as AWS Transfer Family.

### 4. Choose the databases and files

Under **Databases**, tick each database in the formats you want, **CSV**, **MMDB** or both. Under **Files**, choose **Latest only** to keep one copy of each file, or **Every build** to keep a dated folder per build, then click **Save**.

### 5. Test and activate

The first **Test connection** reads the server's host key, pins it and shows its fingerprint, which you can compare with `ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub` on the server. From then on, VPNDetection won't connect to a server presenting any other key. Once the test passes, click **Activate**.

If you change the host key on purpose, click **Forget** beside the pinned one under **Pinned host key**, test again to pin the new key, and activate.

## Set up FTPS

FTPS is FTP over TLS. VPNDetection only delivers over TLS, never plain FTP, which would send your password and the databases in the clear.

### 1. Add the destination

In the [console](https://app.vpndetection.io/database/delivery), under **Database** > **Delivery**, click **Add destination** and pick **FTPS**.

### 2. Enter the server

Under **Connection**, enter the **Host**, pick the TLS mode your server speaks, and enter the **Port**, the **Username**, the **Password** and the **Folder**. **Explicit TLS (port 21)** upgrades the connection with `AUTH TLS`, usually on port 21, and is the more common. **Implicit TLS (port 990)** is TLS from the first byte, usually on port 990.

The server's certificate has to validate. For a self-signed one, turn on **Accept a certificate that doesn't validate**, knowing that anyone between VPNDetection and the server could then read what it sends.

### 3. Choose the databases and files, then test

Choose the databases and files as for SFTP, click **Save**, then **Test connection**, and **Activate** once it passes. A test against a port in the other mode fails, sometimes only after 30 seconds and with a login error, so if a test fails that way, try the other mode.

VPNDetection transfers in passive mode, so the server's passive port range has to accept connections from the internet too, and it speaks TLS 1.2, which every FTPS server supports.

## Verify that a build arrived

A small database lands within a pass or two of activating, and a large one takes as long as its transfer. To confirm it, open the destination's **History** tab: each file sent reads **New build** under **Why** and **Delivered** under **Result**, and the destination's row shows the time under **Last delivered**.

On the server, each file sits in the folder beside its `.sha256`, under its final name, and `manifest.json` lists them all. Run `sha256sum -c vpn_ip_v1.mmdb.sha256` in that folder to confirm that a file is intact.

## When delivery fails

The test result and the **Detail** column in **History** say what failed, in words, and a `database.delivery_failed` event carries the same failure as an `error_code`. The common ones are these:

| `error_code` | Cause | What to do |
| --- | --- | --- |
| `HOST_UNREACHABLE` | The host couldn't be reached. | Check the host and port, and that the server accepts connections from the internet, from any address. |
| `HOST_NOT_PUBLIC` | The host resolves to a private address. | Use a public host name or address. |
| `AUTH_FAILED` | The server turned the sign-in down. | Check that the destination's public key is in the user's `authorized_keys`, or that the password is right. |
| `HOST_KEY_CHANGED` | The server presents a different host key from the one pinned. | If you changed it on purpose, click **Forget**, test again and activate. If you didn't, find out why first. |
| `TLS_FAILED` | The server's certificate didn't validate. | Fix the certificate, or accept a self-signed one in the destination's settings. |
| `NO_SPACE` | The server is out of space or over its quota. | Free space, or keep fewer builds with **Latest only** or **Keep builds for**. |
| `TIMEOUT` | The connection timed out. | For FTPS, try the other TLS mode, and check the passive port range. |

A failed delivery is tried again on a schedule, and after three days of failures the destination is paused until someone resumes it, as [When delivery fails](/integrations/database-delivery#when-delivery-fails) explains.

## Next steps

Your server now receives each new build of the databases you chose. To act on each delivery as it lands, add a [webhook](/integrations/webhooks) and watch for `database.delivered`, or point a job at `manifest.json`, which changes only once a whole pass is in place.
