---
title: "Send and receive invoices by SFTP"
description: "Learn how to give a system that only writes files an SFTP login for sending and collecting invoices."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.certinvo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send and receive invoices by SFTP

Use SFTP when a customer's system can write files but cannot call an API. Each company gets one SFTP login with
four folders. The system drops invoices in, collects an answer for each file, and picks up invoices that
arrived another way.

The login works by SSH key only. It sees only its own four folders and can do nothing but move files.

## 1. Save a key

1. In the console, open **Einstellungen**, then **Verbindungen**, then **SFTP**.
2. Paste the public key of each system that will connect, one key per line.
3. Choose **Schlüssel speichern**.

The first save makes the login and shows the command to connect:

```bash
sftp -P 2222 acme-gmbh-k3f9@sftp.certinvo.com
```

Saving replaces the whole list, so paste every key that should log in. A login holds up to 10 keys. **Schlüssel
speichern** waits until the page has read the current keys.

- An ed25519 key is the best choice. ECDSA keys are accepted too.
- An RSA key needs at least 3072 bits.
- A private key, a key with options in front of it, or the same key twice is refused with 400
  `invalid_sftp_key`.
- An empty list lets nobody in. The username stays.

You can do the same through the API:

- `GET /v1/sftp` returns the username, host, port, the keys by fingerprint, and the last 20 files.
- `GET /v1/arrivals/not-accepted` returns the files that were refused or were duplicates, and the files that
  were filed and then could not be read, with any mails that were not accepted, newest first. `direction=in`
  lists `incoming/`, `direction=out` lists `outgoing/`. A duplicate names the invoice its first file became as
  `invoiceId`. A file that could not be read downloads from `GET /v1/arrivals/not-accepted/{id}/file`, and
  `POST /v1/arrivals/not-accepted/{id}/dismiss` deletes it. A file with a virus has the reason `virus-found`, its
  name in `virus`, and no download.
- `PUT /v1/sftp` with `{"publicKeys": [...]}` saves the keys. Only a signed-in person can save them, because a
  key here opens the company's invoices. An API key gets 401 `session_required`.

## 2. Drop files

| Folder | What goes in | What happens |
| --- | --- | --- |
| `outgoing/` | Invoices the company sends: a finished e-invoice as XML or PDF, our invoice JSON, or the company's own export (CSV, Excel, JSON, XML) | A finished invoice is validated. Our JSON is converted. An export is converted through the one confirmed mapping that fits it. |
| `incoming/` | Invoices the company received from suppliers | Filed as received and checked, like a console upload or an emailed invoice. |
| `results/` | Written by Certinvo | One `<file>.result.json` per file dropped in `outgoing/`, and the invoice files a conversion made. The answers to files dropped in `incoming/` are in `results/incoming/`. |
| `inbox/` | Written by Certinvo | Invoices the company received another way. See step 4. |

A file is taken once it has stopped changing for a few seconds, so a large upload is never read half written.
These are left alone:

- hidden files and folders;
- names ending in `.part`, `.filepart`, `.tmp` and similar upload names.

Once a file is recorded, it is removed from the folder. The invoice itself is kept with its history, as every
upload is.

## 3. Collect the answer

Each dropped file gets one answer in `results/`. For example, `results/RE-1.xml.result.json` answers
`outgoing/RE-1.xml`, and `results/incoming/RE-1.xml.result.json` answers `incoming/RE-1.xml`, so two files of one
name in the two folders never overwrite each other's answer:

```json
{
  "file": "RE-1.xml",
  "folder": "outgoing",
  "status": "filed",
  "operationId": "…",
  "invoices": [{ "index": 0, "invoiceId": "…", "verdict": "clean", "files": [] }]
}
```

The answer also carries `receivedAt`, the time the file was taken.

| `status` | Meaning |
| --- | --- |
| `filed` | The file became one or more invoices, each with its `invoiceId` and `verdict`. A conversion lists the files it made, such as `export.csv.1.ubl.xml`. They lie beside the answer. |
| `refused` | Nothing was filed. `error` holds the code and the sentence the API gives. Examples: a file that is not an invoice, an export no confirmed mapping fits, or an empty file. |
| `duplicate` | The same bytes were dropped before. Nothing new was filed. The answer names the first file and its invoices. |

A file over 25 MB is refused without being read. The plan's own limits still apply after that.

In the console, a file that was `refused` or a `duplicate` is listed in the tab **Nicht angenommen**, the last tab
above the invoice list: a file from `incoming/` under **Eingang**, a file from `outgoing/` under **Ausgang**. A refused
file says why in the console's language, chosen by the code the API gave. A duplicate links to the invoice its first file became, with **Rechnung öffnen**.
A file over 25 MB was never read, so it is answered in `results/` and not listed.

A file that was filed and then could not be read gets a row of its own in **Nicht angenommen**, under its folder
and name. That row stands for the drop, so the drop is listed once. A PDF with no
invoice data inside says **Keine E-Rechnung**. Any other file says **Datei nicht lesbar** and why. Either one can be
downloaded with **Herunterladen** for 30 days, or deleted with **Verwerfen**.

Every dropped file is scanned for viruses before it is filed. A file with a virus is never filed and never kept. Its
answer in `results/` is `refused` with the code `virus_found`. Its row in **Nicht angenommen** says **Virus gefunden:**
and the scanner's name for the virus, and offers only **Verwerfen**. When the virus scan cannot run, the file waits
and is filed once the scan has run.

## 4. Pick up received invoices

Certinvo writes each received invoice to `inbox/`, unless it came in through `incoming/`. This covers invoices
received after the login was made, for example by email or through the API.

- The invoice is written as it arrived, as `<invoiceId>.xml` or `<invoiceId>.pdf`.
- Beside it, `<invoiceId>.json` holds the verdict, the invoice number, the seller and when it arrived.
- The invoice's history gets the line `api:sftp-delivered`.

Your system deletes what it has collected. Certinvo never deletes anything in `results/` or `inbox/`.

## Who may

Making or changing SFTP logins needs an owner, an admin or a developer. Anyone else gets 403 `role_required`. 

## See also

- [Receive invoices by email](/how-to/invoices/receive-invoices-by-email)
- [Send a file through a mapping](/how-to/customer-files/send-a-file-through-a-mapping)
- [Hear every step by webhook](/how-to/invoices/hear-every-step-by-webhook)

Source: https://docs.certinvo.com/how-to/invoices/send-and-receive-invoices-by-sftp/index.mdx
