简体   繁体   中英

Error to connect to FileZilla server using JSch SFTP client

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 (tim.kosse@filezilla-project.org)
(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;

FileZilla is FTP server, not SFTP server.

JSch is SFTP client.

You cannot use JSch to connect to FileZilla server.

You have to use an FTP library, like Apache Commont Net FTPClient .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM