我正在尝试从ftp中检索文件。我遇到以下异常。 有时可以同时访问同一个文件。我的防火墙已关闭。
我的问题是 怎么可以得到这个例外,因为它无法下载necassary文件,我的程序没有使其工作
我的下载代码:
public boolean downloadFile(String sourceFilePath, String destinationDirPath, String newFileName)
throws IllegalStateException {
// final FTPClient client = this.getClient();
FileOutputStream output = null;
try {
client.setFileType(FTP.BINARY_FILE_TYPE);
// The remote filename to be downloaded.
String filename = new File(sourceFilePath).getName();
// Downloads the selected file to the C drive
output = new FileOutputStream(destinationDirPath + File.separator + newFileName);
this.cd(new File(sourceFilePath).getParent());
// Download file from FTP server
boolean result = client.retrieveFile(filename, output);
log.trace("File is downloaded from server:" + filename + ", to destination:"+newFileName);
return result;
}
// Indicate that an exception is occurred while downloading file
catch (Exception ioe) {
throw new FileTransferException("Could not download file", ioe);
} finally {
if (output != null) {
try {
// trying to close FileOutputStream
output.close();
} catch (IOException e) {
log.warn("Error closing writer to file:"+newFileName, e);
}
output = null;
}
}
}
这是堆栈跟踪:
Exception during data transfer, closing data connection socket
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
at org.apache.ftpserver.impl.IODataConnection.transfer(IODataConnection.java:289)
at org.apache.ftpserver.impl.IODataConnection.transferToClient(IODataConnection.java:161)
at org.apache.ftpserver.command.impl.RETR.execute(RETR.java:166)
at org.apache.ftpserver.impl.DefaultFtpHandler.messageReceived(DefaultFtpHandler.java:210)
at org.apache.ftpserver.listener.nio.FtpHandlerAdapter.messageReceived(FtpHandlerAdapter.java:61)
at