gpt4 book ai didi

Java ftp4j - 以 amn 主动模式连接时列出 FTP 服务器中的文件

转载 作者:行者123 更新时间:2023-12-01 11:52:21 27 4
gpt4 key购买 nike

我正在使用 ftp4j 库来实现我的 FTP 客户端,但是我尝试连接的服务器仅在 Activity 模式下接受连接。

因此,当我尝试列出远程文件时,我得到:

ERROR : Error in Connecting to Remote Machine... Hence exitting...
it.sauronsoftware.ftp4j.FTPException [code=501, message= Server cannot accept argument.]
at it.sauronsoftware.ftp4j.FTPClient.openActiveDataTransferChannel(FTPClient.java:3600)
at it.sauronsoftware.ftp4j.FTPClient.openDataTransferChannel(FTPClient.java:3551)
at it.sauronsoftware.ftp4j.FTPClient.listNames(FTPClient.java:2335)
at com.npap.network.TranferFileFtp4j.listRemoteFilesFtp1(TranferFileFtp4j.java:999)

这是代码:

...
//connect to server method - in active mode!
ftpClient = Ftp4jUtility.connect1(SERVER_MACHINE, PORT, SERVER_USERNAME, SERVER_PASSWORD);

try {
ftpClient.changeDirectory(config.getFtpRemoteFolderReports());
log.info("Changed directory to: " + config.getFtpRemoteFolderReports());
} catch (FTPException | FTPIllegalReplyException | IOException | IllegalStateException e) {
e.printStackTrace();
}

String[] filesList = ftpClient.listNames();
for(String f: filesList) {
log.info("fetched file: " + f);
tmpAllRemoteFiles.add(f);
}

在主动模式下连接时有什么方法可以列出远程文件吗?

最佳答案

是的,您可以在 Activity 模式下使用.listNames()

问题可能是服务器无法连接回您的客户端以打开数据连接。您必须在本地防火墙(如果有)上打开 FTP 数据连接范围的端口,并在 NAT(如果有)上路由传入连接。

配置主动模式FTP比较麻烦,很少使用。

了解(我的)关于所需文章 network configuration in respect to FTP active mode .

501 错误代码来自 FTP 服务器(可能是 IIS)。如果您在 google 上搜索“501 Server 无法接受参数”,您会发现很多类似的问题。

你的代码没有任何问题。要么是网络配置问题,要么是服务器端问题。

关于Java ftp4j - 以 amn 主动模式连接时列出 FTP 服务器中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28705328/

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