但是,我正在使用ftp4j库实现我的FTP客户端,这是一台仅在活动模式下尝试连接接受连接的服务器。
因此,当我试图列出我得到的远程文件时:
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);
}在活动模式下连接时,是否有列出远程文件的方法?
发布于 2015-02-25 06:27:31
是的,您可以在活动模式下使用.listNames()。
此问题可能是服务器无法连接回客户端以打开数据连接。您必须打开本地防火墙上FTP数据连接范围的端口(如果有的话),以及路由NAT上的传入连接(如果有的话)。
配置活动模式FTP很麻烦,很少使用。
学习(我的)关于必需FTP活动模式下的网络配置的文章。
501错误代码来自FTP服务器(可能是IIS)。如果你在谷歌上搜索"501服务器不能接受参数“,你会发现很多类似的问题。
你的代码没什么问题。这要么是网络配置问题,要么是服务器端问题。
https://stackoverflow.com/questions/28705328
复制相似问题