Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
harsh__chauhan
Discoverer
2,483

We can Retain Original Filename While Transferring Files Between Two SFTP Servers in SAP CPI

What else we can do:

Receives a file from SFTP Server 1
Extracts the original filename
Transfers the file to SFTP Server 2 while retaining the original filename

What will we doing:

We will explore how to efficiently manage and route files in SAP CPI based on their file type. We'll demonstrate how to:

  • Setup an SFTP free server – This is required to establish an external file storage system. (step – 1)
  • Use FileZilla to connect to the SFTP server, create directories, and upload files – FileZilla is used as a client tool to manage files within the SFTP server. (step – 1)
  • Capture file name and extension dynamically – Extracting file metadata is necessary for conditional processing. (step – 2)
  • Route files based on their extension using a Router – This enables automated decision-making in file handling. (step – 3)
  • Setup Gmail for email notifications – Emails are sent for missing XML files or unexpected file types. (step – 4)
  • Send an alert email when an XML file is missing with proper details of the captured file – Ensures monitoring and error handling. (step – 5)

harsh__chauhan_1-1743659803284.png

Here i have used sftp with poll enrich you can use from start message as well

Scenario Overview

We are dealing with files on an SFTP server:

  1. XML files - To be routed to another SFTP location for further processing.
  2. Other file types - These should trigger an email alert notifying about the unexpected file type.

Step 1: Setup SFTP server, File zilla and SFTP adapter

Here, I have used free SFTP server and used file zilla to create directory and upload files.

Click - https://sftpcloud.io/tools/free-sftp-server  and create

harsh__chauhan_2-1743659803308.png

 

  • Go to CPI tenant > Monitor > Manage security > security material > create > user cred. > set easy name AS YOU HAVE TO USE IT FURTHER.

 

  • What Is Happening in the Configuration?

In SAP CPI > Monitor > Security Material, we create a credential entry with:

Username & password from the SFTP server.

This allows CPI to authenticate and access the server.

harsh__chauhan_3-1743659803323.png

 

 

  • Paste username and pass from sftp server
  • Go to CPI tenant > Monitor > Manage security> connectivity test > SSH> past host from sftp server> click send.

harsh__chauhan_4-1743659803334.png

 

 

  • COPY and Paste in notepad with known.hosts
  • Key Point: What is a Known Host in SAP CPI?
  • Definition: A Known Host is a trusted SFTP server whose SSH fingerprint is stored in SAP CPI for secure authentication.
  • Purpose: Ensures secure SFTP connections by verifying the server’s identity before transferring files.
  • Why It’s Important:

Prevents man-in-the-middle attacks.

Enhances security and compliance.

Ensures only trusted SFTP servers are accessed.

  • How It Works:

CPI checks the SFTP server’s fingerprint against the Known Hosts file.

If the fingerprint matches, the connection is established; otherwise, it is blocked.

 

 

harsh__chauhan_5-1743659803344.png

 

 

  • Now upload the know.hosts file in Manage Security Material > Upload > known host (SSH)
  • Download FileZilla (if the link is not working, search "FileZilla download" on Google).
  • Open > paste host, username, pass and port > quick connect

harsh__chauhan_6-1743659803351.png

 

 

  • Right-click on the empty directory listing and select Create Directory.
  • Create sample files:

sample.xml (valid processing file)

sample.txt (to trigger an alert)

  • OR You can drag and drop to upload the file

 

harsh__chauhan_7-1743659803361.png

 

 

 

Step 2: Configuring SFTP adapter.

harsh__chauhan_8-1743659803367.png

 

Configure Content Modifier to Capturing File Name and Extension

Here, we will use the Content Modifier to extract the file name and extension from the incoming files.

  • Given two files: sample1.txt and sample2.xml.
  • ${file:ext} → Captures only the extension dynamically (e.g. txt or xml).
  • ${file:name} → Captures only the file name dynamically (e.g. sample1 or sample2).

 

                                          SOME MORE EXAMPLES:

file:name → Returns the full name of the file, including the path (e.g., HCI\InputFile.xml).
file:name.ext → Returns only the file extension (e.g., xml).
file:name.noext → Returns the file name without the extension (e.g., HCI\InputFile).
file:onlyname → Returns only the file name with the extension (e.g., InputFile.xml).
file:onlyname.noext → Returns only the file name without the extension (e.g., InputFile).
file:ext → Returns only the file extension (e.g., xml).
file:parent → Returns the parent directory of the file path.
file:path → Returns the full file path.
file:absolute → Returns a boolean indicating if the file path is absolute.
file:absolute.path → Returns the absolute file path.
file:length or file:size → Returns the file size as a Long type.
file:modified → Returns the last modified date of the file as a Date type.

Here we need only name and extension.

harsh__chauhan_9-1743659803373.png

 

Step 3: Routing Files Using Router

The next step is to route files based on their extension using the Router.

Router Configuration:

  • If the file extension is xml, the message is routed to Route 1.
  • If the file extension is not xml, the message is routed to Route 2.
  • If no conditions match, the message is sent to Route 3 (Default Route).

 

harsh__chauhan_10-1743659803378.png

 

FTP – Receiver Side Configuration:

harsh__chauhan_11-1743659803384.png

 

Step 4: Setup mail in SAP CPI (JUMP TO STEP 5 If already Configured.)

harsh__chauhan_12-1743659803401.png

 

 

  • Details > export > save

 

 

harsh__chauhan_13-1743659803405.png

 

 

  • SSL/TLS Encryption Verification

Gmail’s SMTP server uses SSL/TLS encryption to secure communication.

When SAP CPI tries to send an email via smtp.gmail.com, it needs to verify Gmail's identity to ensure it’s not connecting to a fraudulent or malicious server.

The certificate provides proof that the SMTP server is authentic and belongs to Google.

 

 

harsh__chauhan_14-1743659803415.png

 

  • Copy and paste in notepad.

harsh__chauhan_15-1743659803423.png

 

  • Go to monitor in integration suit > Key stores > add > Certificate > fill Alias Name same as APP NAME (not necessary, only for ease) > Add.harsh__chauhan_16-1743659803437.png

     

 

  • Go to Monitor > Security Materials > Create > Name: same as Alias name > username: your mail ID > password: which you copied in notepad (Random password Generated while creating App Name in Gmail) > Deploy.

 

harsh__chauhan_17-1743659803451.png

 

Step 5: Configuring Email Alerts for Missing XML Files

If no XML file is found, an alert email is sent notifying about the missing file.

Mail Adapter Configuration:

  • Address: smtp.gmail.com:465
  • Protection: SMTPS
  • Authentication: encrypted user/pass
  • Credential Name: same as the name of you Created in Security Materials

harsh__chauhan_18-1743659803455.png

 

harsh__chauhan_19-1743659803460.png

 

4 Comments