# Tutorial: Send invoices from SFTP directory

Hooks with the SFTP action are used to connect the PSB and a SFTP server. There are two main flows: the 'from SFTP' flow, which pulls documents from a SFTP server, and the 'to SFTP' flow, which uploads documents to a SFTP server. A tutorial on how to use the 'to flow' can be found here.

# From SFTP

The 'from SFTP' flow periodically pulls files from an SFTP server and uploads them to the PSB. Invoices that need to be sent, for example. The default pull interval is 15 minutes.

For this flow to work, the server needs to have a couple of directories.

Directory Function
Read directory This directory will be read periodically. Files in this directory will be uploaded to the PSB.
Pending directory Files that are uploaded to the PSB will be transfered from the Read directory to Pending.
Duplicate directory Files that are read but are already processed by PSB will be placed here.
Success directory When the operation is completed successfully, the file will be placed here.
Error directory When an error like InvoiceSentError occurs, the file will be placed here. Files that are still retrying, i.e., an InvoiceSentRetry hook was triggered, will stay in the Pending directory.

This flow requires a publish topic, like SendInvoice, to determine what kind of document is used. SFTP actions only support one publish topic per hook. For the flow to work properly, the hook also needs some supporting topics. In the case of publish topic SendInvoice, these are InvoiceSent and InvoiceSentError. For ReceiveInvoice it would be InvoiceReceived and InvoiceReceivedError, etc.

# Configuration

SFTP hooks are registered via the subscribe endpoint on the Hook controller, using the sftp:// action.

The SFTP action consists of three mandatory parts. The first part is the connection info. Here you specify your username and password, as well as the host address and the port of your server. The second part are the directories you use, and the last part is your server's md5 fingerprint: sftp://username:password@host:port?directory1=directory1&directory2=directory2#fingerprint.

From flow example:

"id": "1",
"name": "sftp pull",
"action": "sftp://tester:password@",
"publishTopics": [
"topics": [
"isActive": true,
"createdOn": "2020-11-25T14:42:50.9437103+01:00",
"changedOn": "2020-11-27T16:05:33.9173033+01:00"
© 2021 eConnect International B.V.