cancel
Showing results for 
Search instead for 
Did you mean: 

Get date modified incoming file using SFTP adapter

former_member537554
Participant
1,264

Hello,

Currently we have an integration which reads a CSV file from a server. We would like to read the last modified date of that file as well, in the camel file language it shows that the correct expression is ${date:modified}. However, this is not working in our integration; the property is not filled and does not show up in trace logging.

Can someone tell me whether its possible to read the last modified date of an input file and if yes, which expression is required?

Thanks in advance!

Bram

0 Kudos

Hi,

Does ${file:modified} still valid for SFTP sender adapter in CPI. I am not getting value for it in my integration flow.

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor

Hello Bram,

${file:modified} will get the last modified date of the file read from SFTP.Below will give the whole process you should follow to get the same in readable format.

Script to Convert from TimeObject to readable format:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.json.*;
import groovy.xml.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.*;
import java.util.Date;
import java.io.*
import java.lang.*;
import java.util.*;


def Message processData(Message message) {
    //Body 
       def body = message.getBody();     
       def map = message.getHeaders();
       def value = map.get("FILE_MODIFIED");
       
       Long datetimestamp = Long.parseLong(value.toString().replaceAll("\\D", ""));
       Date date = new Date(datetimestamp);
       DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSS");
       String dateFormatted = formatter.format(date);
       
       map = message.getProperties();
       
       message.setProperty("FileModifiedDate", dateFormatted);
       return message;
}

Regards,

Sriprasad Shivaram Bhat

former_member537554
Participant
0 Kudos

Thanks helping out Sriprasad, this is exactly what I was looking for.

Have a great day!

To add to this, the "CamelFileLastModified" header needs to be defined in the "allowed headers" field of the runtime configuration of the iFlow in order for the above solution to work:

Alternatively, a wildcard can be used to retrieve all file headers:

Answers (0)