2

I need to check the health of the SFTP connection. How to check SFTP connection successful or not in Spring boot(with a try-catch)? Which library should I use to check the SFTP connection in Spring?

Muhammad Saimon
  • 213
  • 2
  • 8
  • 1
    Hi Saimon, I would like to suggest you to use `JSCH` library. You can manually check SFTP authentication and path as well with this. Better of you add more tags like : **JAVA**, **spring-integration** Thanks. – Towfiqul Islam Jun 15 '20 at 00:51

1 Answers1

1

Please check this link. Hope you will get your answer. Though I am copying some code snippet for your help.

.....
jsch = new JSch();
session = jsch.getSession(user, hostIP, port);
session.setPassword(Password);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect(getTimeInSecond() * 1000);
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp) channel;
channelSftp.cd(LocationPath);
...

Thanks

Towfiqul Islam
  • 264
  • 4
  • 12