我正在使用 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);
}
在活动模式下连接时有什么方法可以列出远程文件?