Skip to Content

SFTP File Lookup using User Defined Function

Hello !

In one of the requirements , we have proxy to SuccessFactors(sfsf adapter) scenario in which we need to validate records from proxy with the records in external excel file provided on the sftp server. If the ID(unique no.) is same as provided in the File then we have to send that record else we need to suppress that record on the mapping level .

This can correlate with the following Scenarios: 

1. When we need to get additional data after the sender’s data or when we need to validate some data .

2. When we need to get some dynamic values from secondary sender  .

To achieve this , we need to lookup on the SFTP server for excel File using UDF in the message mapping .

Configuration Required :

com.jcraft.jsch.jar  should be imported .


Before writing the UDF code , we need to import com.jcraft.jsch  external jar file through imported Archive in Enterprise Service Repository(ESR) like this :

Jar file can be found at the below link provided :

Next , We need to use this Imported Archive in Message Mapping . for this we go to functions tab of Graphical mapping and add imported archive as:

After doing this , We should import com.jcraft.jsch.* in th UDF as:

Now we need to write following code in the UDF :

        JSch jsch = new JSch(); //Jsch Object
        Session session = null; //For initializing Session
       String Data = null ;
        try {
            session = jsch.getSession("<username>", "<sftp client>", 22);
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no"); //if we are not checking fingerprints 
            com.jcraft.jsch.Channel channel = session.openChannel("sftp");
            ChannelSftp sftpChannel = (ChannelSftp) channel;
           InputStream stream = sftpChannel.get("/newFile.xls");
           BufferedReader br = new BufferedReader(new InputStreamReader(stream));
      	   StringBuilder response = new StringBuilder();
           String line = "";
               try{  while (line != null) {
                    line = br.readLine();
                  }catch(Exception e)
                    { System.out.print(e); }
            session.disconnect(); //ending Sessions
            Data = response.toString();
             catch (JSchException e) 
            catch (SftpException e) {
return Data;


In this way we can achieve this requirement  .



Thankyou  🙂 .

You must be Logged on to comment or reply to a post.