Post Iterator rule to archive remote CSV file

Hi Team,

We require a post-iterator rule to archive a remote CSV file after account aggregation. Our proof of concept revealed that the post-iterator rule functions only when the CSV file is located on the application server. However, our CSV resides on an FTP server, and we employ SFTP to load the CSV data into SailPoint.

We are seeking a solution to archive this remote CSV file after account aggregation.

Kind Regards,
Hemant

@nailwalnavistar
Check this if it helps you

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="Archive Remote CSV" type="PostIterator">
  <Description>Archives the remote CSV file on the FTP server after account aggregation.</Description>
  <Source>
    <![CDATA[
      import sailpoint.object.*;
      import sailpoint.api.Provisioner;
      import java.io.InputStream;
      import java.io.OutputStream;
      import com.jcraft.jsch.Channel;
      import com.jcraft.jsch.ChannelSftp;
      import com.jcraft.jsch.JSch;
      import com.jcraft.jsch.Session;

      // FTP server details
      String ftpHost = "ftp.example.com"; 
      String ftpUser = "username";
      String ftpPassword = "password";
      int ftpPort = 22;
      
      // CSV file path on FTP server
      String remoteFilePath = "/path/to/file.csv";
      
      // Archive directory on FTP server 
      String archiveDir = "/path/to/archive/";

      try {
          // Create a new SFTP session
          JSch jsch = new JSch();
          Session session = jsch.getSession(ftpUser, ftpHost, ftpPort);
          session.setPassword(ftpPassword);
          session.setConfig("StrictHostKeyChecking", "no");
          session.connect();

          // Open SFTP channel
          Channel channel = session.openChannel("sftp");
          channel.connect();
          ChannelSftp sftpChannel = (ChannelSftp) channel;

          // Move file to archive directory
          sftpChannel.rename(remoteFilePath, archiveDir + "file.csv");

          // Close SFTP channel and session
          sftpChannel.exit();
          session.disconnect();

          // Log success message  
          log.info("Successfully archived remote CSV file: " + remoteFilePath);

      } catch (Exception e) {
          // Log any errors
          log.error("Error archiving remote CSV file: " + e.getMessage());
      }
    ]]>
  </Source>
</Rule>

You should have the JSch library in SailPoint server and required permissions to rename files on the FTP server.

1 Like

Hi @nailwalnavistar,

To add on to other expert’s answer.
You may try below code and if you are using 8.4 then this jar “sshj-0.31.0.jar” is present in OOTB and not external jar import is needed.

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;

String sftpHost = "your.sftp.server.com";
        String sftpUser = "yourUsername";
        String sftpPassword = "yourPassword";
        String localFilePath = "path/to/local/file.txt";
        String remoteFilePath = "/path/to/remote/archive/file.txt";

        SSHClient sshClient = new SSHClient();
        try {
            sshClient.addHostKeyVerifier(new PromiscuousVerifier());
            sshClient.connect(sftpHost);
            sshClient.authPassword(sftpUser, sftpPassword);

            SFTPClient sftpClient = sshClient.newSFTPClient();
            sftpClient.put(localFilePath, remoteFilePath);

            System.out.println("File archived successfully at SFTP location.");

            sftpClient.close();
            sshClient.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.