Receiver sFTP Adapter Configuration

Complete guide to sFTP receiver adapter Communication Channel configuration in SAP PI/PO. Each configuration’s parameter functionality explained in detail.

In this article, we will look at these settings in sFTP Adapter,

  1. sFTP Adapter Transport Protocol, Message Protocol, and Adapter Engine Configuration.
  2. sFTP Receiver Server Destination Configuration.
  3. Authentication Methods of sFTP Channel.
  4. sFTP File Name and Directory Configuration.
  5. sFTP Processing Parameters, Timestamp to File Name, Message-ID to File Name, Write Mode, etc.
  6. Run Operating System (OS) Command in Receiver sFTP Adapter.
  7. Advance Variable Substitution for sFTP File Path and File Name.
  8. Adapter Specific Message Attributes (ASMA) of sFTP Receiver Communication Channel.
  9. Communication Channel Adapter Status.
  10. File Archiving technique.

You can also connect SAP directly with FTP file server and create files.

SAP Versions used in the illustration:

  • SAP PO 7.5

sFTP Adapter Transport Protocol, Message Protocol and Adapter Engine Configuration.

Adapter type ‘sFTP’ has only one Transport Protocol which is ‘SFTP’ itself. Depending on your PI/PO version you can configure the Adapter Engine. Usually, the default Adapter Engine is ‘Central Adapter Engine’ and it will be populated automatically.

Message Protocol – File Content Conversion.

Message protocol configuration of sFTP Adapter in SAP PI/PO
Message Protocols of sFTP Adapter

If the target message (file) created by Message Mapping needs to be converted by the Receiver Adapter Communication Channel select the option ‘File Content Conversion‘. Usually, if the receiver file format is anything other than XML, you can use this feature to convert the file to an appropriate format such as CSV, Text, etc.


sFTP Receiver Server Destination Configuration.

sFTP Server, Port and Server Finterprint Configuration in Communication Channel
Server TCP/IP, Port, Timeout and Fingerprint

Server

Defines the TCP/IP of the sFTP server. It can be configured as a host name or IP address.

Port

Default sFTP port is ’22’. This Parameter defines the Port of the sFTP server.

Timeout (ms)

The timeout parameter defines how long the transmitted file remains unacknowledged by the receiver sFTP server. After the defined time (ms), when receiver Communication Channel terminates the connection, set the message to error status and log the error in Message Log.

Server Fingerprint

When you connect to the sFTp server for the first time using any sFTP/FTP clients such as FileZilla, WinSCP, etc., Server Fingerprint will be promoted.


Authentication Methods of sFTP Channel.

There are three Authentication Methods in sFTP adapter:

Authentication methods on sFTP Communication Channel. Password, Private Key and Duel Authentication
Authentication methods on sFTP Communication Channel
  • Password
  • Private Key
  • Duel Authentication

sFTP Authentication Method ‘Password’.

Password method authenticates the connection with the sFTP server using Username Password combination.

sFTP Authentication using Password
sFTP Authentication using Password

sFTP Authentication Method ‘Private Key’.

Authentication using ‘Private Key‘ method allows us to connect to sFTP server in a more secure way. During design time, system administrators of PI/PO system and sFTP server owners should exchange respective ‘Public Keys’ and install them. Public Key of sFTP host should be installed in PI/PO server and vice versa.

System Administrators (BASIS) maintain the SSH keys in Key Store under ‘Certificates and Keys‘ section of ‘Netweaver Administrator

SAP Netweaver Administrator > Configuration > Security > Certificates and Keys.

Configuration and installation of Certificates and keys.
Certificates and Keys views of PI/PO can be viewed under NWA.

In older versions of SAP PI or XI key store can be accessed under,

NWA > Configuration Management > Security > Certificates and Keys > Key Storage > Content > Keystore Views.

What we configure with Private Key View and Private Key Entry parameters is the SAP PI/PO’s Private Key information. During the system setup (configuration) only Public Keys of the servers are exchanged and installed. At the time of actual connection or handshake with sFTP, Private Key configured in the Communication Channel and Public Key installed in sFTP combination decrypt the data and allow the connection.

Username is the sFTP username.

sFTP Private Key configuration.
Authentication using Private Key

sFTP Authentication Method ‘Duel Authentication’.

sFTP dual authentication configuration
Dual Authentication in sFTP Adapter

This is simply a combination of ‘Password‘-based authentication and ‘Private Key‘-based authentication.


sFTP File Name and Directory Configuration.

There are several ways to configure the File Name and Directory of receiver files. You can do it by using parameters in the receiver Communication Channel or set the file names dynamically at run-time.

sFTp Adapter filename and directory configuration
File parameters, File name and Directory of sFTP adapter.

The configuration above defines the receiver file name as ‘test.xml‘, and files will be generated in directory ‘/home/username/in/test/’. Prefix ‘~’ defines the home directory of the user configured in ‘Authentication Method’.

You can also define directory without the prefix ‘~’.

You can set the filename and directory dynamically using any of the methods below. Check my previous posts on in-detail examples of each method.


sFTP Processing Parameters, Timestamp to File Name, Message-ID to File Name, Write Mode, etc.

Add Timestamp to filename.

Add the timestamp in format YYYYMMDD_HHMMSS-xxx before the extension of the filename. If the configuration is activated and File Name parameter is set as ‘Test_.XML’, the name of the receiver files will be set as Test_YYYYMMDD_HHMMSS-xxx.XML. ‘xxx’ is a random sequence number generated by Adapter Engine.

Add Message-ID to file name.

Add the PI Message ID to the file name. This is a great way to avoid overwriting files at the receiver by keeping the file name unique.

Write Mode — Direct.

Files are written directly to the specified folder in File Parameter’s Directory.

Write Mode — Temporary Mode.

Files are written at the receiver under temporary names before being converted to the specified format in Communication Channel. Even with timestamp in the filename, there is a possibility of overwriting files when large number of files are generated at the same time (same second). This is the best method to use if there is a chance of receiver picking up the files and processing them while they are being generated by PI/PO. Temporary mode creates each file with a unique name and changes the filename to specified format after file generation is completed.

In Temporary File mode, file names are first set as <timestamp><file name>.tmp. Time stamp here is up to millisecond.

Empty File Handling.

Setting this parameter as ‘Write Empty File will allow you to create empty file in the target directory. Otherwise set it as ‘Ignore‘ so empty files are not created at the receiver directory.

Store Attachments.

Allow the adapter to save attachments in the PI message and in the target directory.


Run Operating System (OS) Command in Receiver sFTP Adapter.

These two parameters allow us to run OS commands before and after message processing. OS scripts should be defined in Command Line parameter.

Configure Operating System (OS) Commands in Receiver sFTP Adapter
Configure Operating System (OS) Commands in Receiver sFTP Adapter

Advance Variable Substitution for sFTP File Path and File Name.

Parameters defined in ‘Filename’ or ‘Directory’ can be replaced by message payload attributes using this option. For example, replace the file name with a field value from a target message (after Message Mapping). Check out my previous post on how to set the Purchase Order number in the target message to file name using the Variable Substitution method.

Variable Substitution Configuration in Receiver sFTP Adapter
Variable Substitution Configuration

Enable Security Check if you want to validate the Directory path for characters such as ‘.’, ‘\’, ‘/‘. If these characters are found after the variable substitution, message is set to error.

Adapter Specific Message Attributes (ASMA) of sFTP Receiver Communication Channel.

Filename and Directory can be copied from the incoming message using ASMA. sFTP Adaper Specific Message Attributes are included under namespace ‘http://sap.com/xi/XI/System’.

In order to use these attributes, you also need to set ASMA in the sender adapter Communication Channel.

Go to message content’s Dynamic Configuration to view these attributes.

Dynamic Configuration section of PI/PO message holds the filename and directory attributes of the sFTP adapter.
Dynamic Configuration section of PI/PO message

Notice the FileName and Directory attributes under “http://sap.com/xi/XI/System/File” namespace. These are automatically set from Sender sFTP Adapter Communication Channel when ASMA is activated. Use them in the Receiver Adapter using Dynamic File Name generation methods.

<?xml version="1.0" encoding="utf-8" ?>
<sap:DynamicConfiguration xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sap="http://sap.com/xi/XI/Message/30">
<sap:Record namespace="http://sap.com/xi/XI/Message/30/routing" name="SourceMessageType"/>
<sap:Record namespace="http://sap.com/xi/XI/System/File" name="Directory">/out/test/</sap:Record>
<sap:Record namespace="http://sap.com/xi/XI/Message/30/routing" name="InterfaceDeterminationHash">60fde8e2912f3f0ae7109f852b1f7f08</sap:Record>
<sap:Record namespace="http://sap.com/xi/XI/Message/30/routing" name="SourceMessageTypeNS"/>
<sap:Record namespace="http://sap.com/xi/XI/Message/30/routing" name="InterfaceFromOperation"/>
<sap:Record namespace="http://sap.com/xi/XI/Message/30/general" name="senderAgreementGUID">11ce9cb7133b3e50a27ac679e2e0772b</sap:Record>
<sap:Record namespace="http://sap.com/xi/XI/System/File" name="FileName">test_20190223-133040-125.xml</sap:Record>
</sap:DynamicConfiguration>


Communication Channel Adapter Status.

If adapter status is ‘Active“, adapter is allowed to exchange messages. If the status is ‘Inactive‘, Communication Channel is blocked from exchanging messages.

sFTP Receiver Adapter Status
Receiver Communication Channel Adapter Status

Archiving of Files.

Archiving configuration allows you to save the files in your PI/PO server. Archive Name parameter defines the location (Directory) of the archive files saved.

Use these substitution parameters to define the Archive location of the PI/PO server.

  • %SEQNUM: A sequence number, starting with 1
  • %RTSEQNUM: A server wide sequence number, starting with 1
  • %START: The start time of the adapter
  • %TIME: The archiving period in milliseconds
  • %MSGID: The XI message ID

if you have any questions on sFTP receiver Adapter configuration or any of the parameters of the Communication Channel, please leave a comment below.

19 thoughts on “Receiver sFTP Adapter Configuration

  1. deepu says:

    Hi Fernando,

    As usual great blog for configuring the Receiver SFTP Channel.

    As SFTP team shares the public key with Basis team.Please provide the configuration required in Certificate and keys step after we receive the Public key.In Which format we need to accept the key from SFTP team feasible for PI/PO. what are the open ssl commands for generating our public key and sharing to SFTP team.

    Thanks.

  2. deepu says:

    Hi Fernando,

    Great blog

    Can i have the list of steps required to configure in Certificate and keys for Public key generation.

    Thanks.

  3. Robert says:

    Hi Isuru ,
    With SFTP we are constantly getting connection reset alerts from the SFTP adapter.
    With FTP we had the option to set a “per file transfer” parameter .
    Is there an option with the SFTP adapter to do the same ?

  4. Sandeep says:

    Great blog Isuru Sir as usula..
    Request to you please post a blog on certificate based authentication in SAP PI/PO.

  5. Javier Villarreal says:

    Hello Isuru,

    thanks a lot for your excellent and informative tutorials.
    I have a simple question, i hace a file to sFTP interface and would like to use the same file name from the source to the destination, with no changes. I can’t find the way or haven’t understand how to achieve this.
    Shoud i just set the filename check box in ASMA and use a variable name like the default “FileName” and then in the destination tab choose FileName as my Filename?
    would it be: %FileName

    thank you so much
    Javier Villarreal
    jvillarrealp@gruma.com

  6. Parvinder Kaur says:

    Great Work!!
    This blog is something which I was looking for. It would be more interesting if we get the screenshot of the particular topic for more clear understanding.
    Thanks Again 🙂

  7. Fernando Oliveira says:

    Hello Fernando!
    Thanks for the post. Helped me a lot.
    I need to replace files in the destination directory. Do you know if it is possible to do so? (SAP PI 7.4)

      • Fernando Oliveira says:

        The “OverWrite” checkbox below the “Create Directory” checkbox?
        It is checked, but the files keep duplicating: Ex: File1.txt, File1_1.txt, File1_2.txt
        I really need to meet this requirement (always overwrite the files), but I haven’t found any documentation or example.

        Thank you very much!

          • Fernando Oliveira says:

            Hi Hari,
            I managed to solve it! In the “Advanced” tab, check the “Advanced Mod” and include the parameter
            attachmentName.overwrite Value: true

            If you want to keep the original name, you can also include:
            retain.attachment.name true
            🙂

  8. Kranthi says:

    Hello Isuru,

    This post helps us alot to configure sFTP adapter.
    Could you please share few steps like how to fetch detail error message from message logs in adapter engine

  9. ajay says:

    can we exclude file naming extension in target SFTP channel ..
    ex:
    source file name: abc.csv
    expected target file name : abc
    fyi: file name is dynamic and ASMA ticked for same

Leave a Reply

Your email address will not be published. Required fields are marked *