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)
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:
XML files – To be routed to another SFTP location for further processing.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
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.
Paste username and pass from sftp serverGo to CPI tenant > Monitor > Manage security> connectivity test > SSH> past host from sftp server> click send.
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.
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
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
Step 2: Configuring SFTP adapter.
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., HCIInputFile.xml).
file:name.ext → Returns only the file extension (e.g., xml).
file:name.noext → Returns the file name without the extension (e.g., HCIInputFile).
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.
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).
FTP – Receiver Side Configuration:
Step 4: Setup mail in SAP CPI (JUMP TO STEP 5 If already Configured.)
Open https://mail.google.com/ Download Certificate > Connection is secured > Certificate is valid >
Details > export > save
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.
Open https://myaccount.google.com/ > Search “ app passwords ” > write any name in APP NAME e.g. “GMAIL OR MAIL OR ANY ” – > create .
Copy and paste in notepad.
Go to monitor in integration suit > Key stores > add > Certificate > fill Alias Name same as APP NAME (not necessary, only for ease) > Add.
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.
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:465Protection: SMTPSAuthentication: encrypted user/pass Credential Name: same as the name of you Created in Security Materials
Read More Technology Blogs by Members articles
#abap