I'm trying to connect on SFTP using localhost configurations but I get the following error. But when I use the same configurations on FilleZilla it works perfect...
At FilleZilla server:
(000017)06/08/2019 09:26:20 - (not logged in) (127.0.0.1)> Connected on port 21, sending welcome message...
(000017)06/08/2019 09:26:20 - (not logged in) (127.0.0.1)> 220-FileZilla Server 0.9.60 beta
(000017)06/08/2019 09:26:20 - (not logged in) (127.0.0.1)> 220-written by Tim Kosse ([email protected])
(000017)06/08/2019 09:26:20 - (not logged in) (127.0.0.1)> 220 Please visit https://filezilla-project.org/
(000017)06/08/2019 09:26:20 - (not logged in) (127.0.0.1)> SSH-2.0-JSCH-0.1.54
(000017)06/08/2019 09:26:20 - (not logged in) (127.0.0.1)> 500 Syntax error, command unrecognized.
(000017)06/08/2019 09:27:21 - (not logged in) (127.0.0.1)> 421 Login time exceeded. Closing control connection.
(000017)06/08/2019 09:27:21 - (not logged in) (127.0.0.1)> disconnected.
Here is the error in Java:
com.jcraft.jsch.JSchException: connection is closed by foreign host
at com.jcraft.jsch.Session.connect(Session.java:269)
at com.jcraft.jsch.Session.connect(Session.java:183)
at br.com.wasys.nps.service.SftpService.test(SftpService.java:26)
Here is my Java code:
JSch jsch = new JSch();
Session session = jsch.getSession("test", "localhost", 21);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("root");
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = channel;