SFTP for EDI messages over AS2
Aug 14, 2020 • Kumudika Rupasinghe ~ 4 min to read

SFTP for EDI messages over AS2

Integrating SFTP for EDI messages over AS2

When sending/receiving a large number of documents over AS2, it’s better to use an integration mechanism like SFTP. SFTP can easily support bulk file transfers as well as large file transfers. And also, if you prefer to integrate internal systems with your trading platform, it’s a perfect choice for you to go with MFT Gateway SFTP connectivity which you can configure to automate message flow.

MFT Gateway uses AWS Transfer Family service for SFTP integration. Therefore you can easily transfer files directly into and out of your Amazon S3 bucket. Let’s see how we can integrate SFTP in MFT Gateway.

How to integrate the SFTP?

Log in to the MFT Gateway console and click on the Integrations icon from the left-hand side menu bar. There are two integrations as S3 Integration and SFTP Integration. Our previous article Integrating AWS S3 for EDI messages over AS2 explains more about S3 integration. For this article, let’s focus on SFTP integration.

SFTP Settings

MFT Gateway allows SFTP access via key-based authentication. You can either use an existing SSH key pair generated by yourself or let MFT Gateway generate a new key pair on behalf of you.

To integrate SFTP,

  1. provide a suitable username;
  2. if you already have a key pair, put a tick on Enabling with existing public key, provide that existing public key, and click Enable SFTP button.
  3. if you don’t have a key pair, click Enable SFTP button right after giving the SFTP username and the private key will be downloaded.

MFT Gateway does not store your credentials, and keys can not be recovered if you lose them. So, save it somewhere safe. But in case you misplaced your current private key, you can always disable the existing SFTP account and create a new SFTP account at any time.

SFTP Enabled View

Login to SFTP Server

Once you have created the SFTP account, you can connect to the SFTP server by running the following command. Make sure to replace <private-key-path> with the location of your private key and <sftp-username> with your SFTP username.

sftp -i <private-key-path> <sftp-username>@sftp.mftgateway.com

When running the above command, you might get the below error.

Key Permission

The reason for the above error is your private key file permissions are too open. It must not be publicly viewable. So, set permissions by running this command, replacing <private-key-path> with your private key location:

chmod 400 <private-key-path>

Once you have successfully connected to the SFTP server, you can find a folder named AS2 including subfolders files, headers, raw-mdn and raw-message, which correspond to different aspects of your AS2 message flow such as attachments, MDNs, and HTTP header traces.

Send an AS2 message

Once you have set up your trading stations and partners from the MFT Gateway console, you can send your AS2 messages via SFTP by uploading relevant files to the send folder (AS2/send/<station-AS2-id>/<partner-AS2-id>/). MFT Gateway will pick them up and send them to your trading partner.

To upload an attachment from the local directory to the send folder, type the following command, replacing <local-file>, <station-AS2-id>, <partner-AS2-id>, <attachment-name> with correct values:

put <local-file> AS2/send/<station-AS2-id>/<partner-AS2-id>/<attachment-name>

Example output: Put

The file will be picked up and sent to the relevant partner. Once the message is successfully sent, the attachment will be moved to the following path:


Download sent attachments to a local directory

If you want to download a sent attachment to a local directory, type this command; replacing necessary components:

get AS2/files/<station-AS2-id>/<partner-AS2-id>/outbox/<timestamp-random-number>/<attachment-name> <local-path>

Example output: Download sent attachments

As you saw above, in the outbox MFT Gateway keeps attachments of each AS2 message in a separate directory named as <timestamp-random-number> If you want to list all the attachments in the outbox, type this command; replacing <station-AS2-id> and <partner-AS2-id> with correct values:

ls AS2/files/<station-AS2-id>/<partner-AS2-id>/outbox/

list all attachments in outbox

List received attachments

Similarly, if you want to list all the attachments in the inbox, run this command, replacing <station-AS2-id>, <partner-AS2-id> with correct values:

ls AS2/files/<station-AS2-id>/<partner-AS2-id>/inbox/

list all attachments in inbox

Download received attachments to a local directory

If you want to download an attachment of a received message to a local directory, type this command replacing necessary components.

get AS2/files/<station-AS2-id>/<partner-AS2-id>/inbox/<timestamp-random-number>/<attachment-name> <local-path>

Example output: Download received attachments

Sign Up for 30 day Free Trial! Stay tuned for more updates!