gpt4 book ai didi

java - 使用 JSch SFTP 客户端连接到 FileZilla 服务器时出错

转载 作者:行者123 更新时间:2023-12-02 01:22:55 63 4
gpt4 key购买 nike

我尝试使用本地主机配置连接 SFTP,但出现以下错误。但是当我在 FilleZilla 上使用相同的配置时,它工作得非常完美......

在 FilleZilla 服务器:

(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.

这是 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)

这是我的 Java 代码:

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 是 FTP 服务器,而不是 SFTP 服务器。

JSch 是 SFTP 客户端。

您无法使用 JSch 连接到 FileZilla 服务器。

您必须使用 FTP 库,例如 Apache Commont Net FTPClient .

关于java - 使用 JSch SFTP 客户端连接到 FileZilla 服务器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57376061/

63 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com