[SAP CPI] – HOW TO FILTER FILE WHEN WORKING WITH SFTP

Hi guys, in this article I share one mini scenario when working with SFTP.

Scenario

Integration Flow want get all files with extension XML from folder SFTP into flow. Do some logic and then will sent payload into queue.

Queue is JMS adapter.

All information of SFTP, ex: address, folder, credential… will be set by parameter.

This is integration flow of this scenario

#1. Configuration sender adapter

#2. Configuration SFTP sender adapter

In this configuration, we will use externalize parameter to config dynamic value for SFTP.

This is parameter table for this configuration

#3. Configuration Content Modifier

In this content modifier, we will create header with name CAMELFILENAME to get extension of file which get from SFTP folder.

When working with File, we can get some information of FILE as

${file.name}Get full file with extensionHCI\InputFile.xml
${file:name.ext}Get extension of filexml
${file:name.noext}Get file with no extensionHCI\InputFile
${file:onlyname}Get file nameInputFile.xml
${file:onlyname.noext}Get file name no extensionInputFile
${file:ext}Get extension xml

#4. Configuration Router

Base on value of HEADER.CAMELFILENAME, we set condition in router to get just file with extension is XML

#5. Configuration for queue. JMS receiver adapter

#6. Input value for parameters

After save, we need to input value for parameters which we define in integration flow.

Go to artifact, choose configure.

#7. Test from POSTMAN

In this step, we will do test script as

  • First, send file with extension NOT equal XML. (Ex: ZIP file). In this case flow will run router default (Route 2), and we will receiver ABC as payload
  • Second, send file with extension EQUAL XML, in this case flow will run route 1, and we will receiver data in JMS (data in JMS queue will be decrypt)
  • Check in queue

Summary

This article just a small, very small scenario in real project, but it can help me, newbie in CPI can take more understand. And It’s very interested and thankful if I receive any advise from you. Thanks for your reading and any question or advise, kindly leave your comment on this.

Joseph.

One comment

  1. Hi Huy,
    It is a very nice blog. thanks for sharing such a brief explanation step by step. I am a beginner. i have requirment. I have to pick files from SFTP and process them to another system using the Odata service. when the file is failing to process to Target due to a connection or mapping error it has to move to the error backup folder. and should delete in the source location as well. whenever a connection is established target end, the file has to reprocess from error folder automatically. Can you suggest how to achieve this?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.