cancel
Showing results for 
Search instead for 
Did you mean: 

Handling multiple files from ECC proxy to SFTP in SAP PI

0 Kudos

Hi Experts,

i've scenario where we were getting two flat files as attachments to proxy interface with two fields(file name & Date) with these fields we need create the folder in SFTP server and place both files in to the same folder(which we created in SFTP with the help of date filed).

could you please suggest us here?

Accepted Solutions (0)

Answers (1)

Answers (1)

anupam_ghosh2
Active Contributor

Hi sekharvcs,

you can achieve this using java mapping and use of API in java mapping.

java mapping will read attachments as per this blog.

Then write the attachment as files to SFTP server. with help of below method using API described above.

public void whenUploadFileUsingVfs_thenSuccess() throws IOException {
    FileSystemManager manager = VFS.getManager();
 
    FileObject local = manager.resolveFile(
      System.getProperty("user.dir") + "/" + localFile);
    FileObject remote = manager.resolveFile(
      "sftp://" + username + ":" + password + "@" + remoteHost + "/" + remoteDir + "vfsFile.txt");
 
    remote.copyFrom(local, Selectors.SELECT_SELF);
 
    local.close();
    remote.close();
}

Note that the local file path should be absolute, and the remote file path should start with sftp://username:password@remoteHost.

Then if there is no exception raised error message can be mailed to PI team for instances when SFTP server is down or has authorization issues. If writing is successful then mail message will inform team accordingly.

The use of mail adapter can be found in this blog.

The mail adapter is being used so that to know if writing to SFTP server was successful or not (and is optional).

If you do not use mail adapter you can replace the same with any other adapters to see result of operation performed.

Regards

Anupam