I have a requirement where I want to use spring integration but don't want to use spring boot to download the file from sftp server. I am using jcraft library here. Want to use spring-integration libraries.
public void downloadFileFromSftpServer () {
String hostname = "XXX";
String username = "XXX";
String password = "XXX";
String copyFrom = "XXX";
String copyTo = "XXX";
JSch jsch = new JSch();
Session session;
System.out.println("Trying to connect.....");
try {
session = jsch.getSession(username, hostname, 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
System.out.println ("Connection successful.");
ChannelSftp sftpChannel = (ChannelSftp) channel;
Vector <ChannelSftp.LsEntry> vector = (Vector<ChannelSftp.LsEntry>) sftpChannel.ls(copyFrom);
ChannelSftp.LsEntry list = vector.get(0);
System.out.println(list.getFileName());
String oldestFile =list.getFilename();
sftpChannel.get(copyFrom+oldestFile, copyTo);
}
See the Spring Integration Documentation. It uses jsch too.
It does not need Spring Boot, it can be used in any Java/JVM application; Spring Integration has existed much longer than Spring Boot.