Post Iterator rule to archive remote CSV file

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