# Tutorial: Send invoices from SFTP directory

Hooks with the SFTP action are used to connect the PSB and an 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 must have a read directory.

It is also possible to configure status directories, meaning files will be moved to their respective status directories after being processed. If no status directories have been configured, the file will be removed from the read directory when it is processed.

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 transferred 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@127.0.0.1:22?readDirectory=/&pendingDirectory=/pending/&errorDirectory=error/&successDirectory=success&duplicateDirectory=/duplicates#5B-66-81-DC-47-3D-AC-D0-04-46-FB-F2-98-30-74-41",
"publishTopics": [
"SendInvoice"
],
"topics": [
"InvoiceSent",
"InvoiceSentError"
],
"isActive": true,
"createdOn": "2020-11-25T14:42:50.9437103+01:00",
"changedOn": "2020-11-27T16:05:33.9173033+01:00"
}

By default the SendInvoice or SendOrder command is routed to Peppol. However, it is also possible to route them to other networks like DICO or Coupa. Please contact us for more information.

© 2024 eConnect International B.V.