您好我编写的程序需要使用apache commons从ftp下载一些文件,但是当我尝试下载时,程序会创建一个零字节文件并转到下一个文件。这是我的代码:
String FTPPath = link.attr("href");
URL url = new URL(FTPPath);
String host = url.getHost();
FTPClient client = new FTPClient();
client.connect(host);
client.login("anonymous", "anonymous");
boolean success = client.changeWorkingDirectory(url.getPath());
FTPFile[] list = client.listFiles();
// boolean success = client.changeWorkingDirectory(url.getPath());
for (FTPFile f : list) {
String fileName = f.getName();
if(fileName.endsWith(".raw")){
System.out.println(fileName + " Downloading");
//client.download(fileName, new java.io.File(fileName));
String remoteFile1 = f.getLink();
File downloadFile1 = new File(fileName);
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
success = client.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
if (success) {
System.out.println(fileName +" has been downloaded successfully.");
}
}
}
}
成功变量显然是假的。但是我没有收到任何其他错误消息。
以下是我尝试下载的其中一个ftps的示例。
ftp://ftp.pride.ebi.ac.uk/pride/data/archive/2015/11/PXD000918