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,
- sFTP Adapter Transport Protocol, Message Protocol, and Adapter Engine Configuration.
- sFTP Receiver Server Destination Configuration.
- Authentication Methods of sFTP Channel.
- sFTP File Name and Directory Configuration.
- sFTP Processing Parameters, Timestamp to File Name, Message-ID to File Name, Write Mode, etc.
- Run Operating System (OS) Command in Receiver sFTP Adapter.
- Advance Variable Substitution for sFTP File Path and File Name.
- Adapter Specific Message Attributes (ASMA) of sFTP Receiver Communication Channel.
- Communication Channel Adapter Status.
- 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.
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.
Defines the TCP/IP of the sFTP server. It can be configured as a host name or IP address.
Default sFTP port is ’22’. This Parameter defines the Port of the sFTP server.
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.
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:
- Private Key
- Duel Authentication
sFTP Authentication Method ‘Password’.
Password method authenticates the connection with the sFTP server using Username Password combination.
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.
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 Authentication Method ‘Duel Authentication’.
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.
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.
- Set the filename and directory using a User Defined Function (UDF)
- Using Adapter Specific Message Attributes (ASMA)
- Variable Substitution
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.
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.
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.
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.
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>
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.
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.