0

我正在尝试从 ftp 检索文件。我收到以下异常。有时可能会并发访问同一文件。我的防火墙已关闭。

我的问题是如何摆脱这个异常,因为它无法下载必要的文件,我的程序无法正常工作

我的下载代码:

    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 
4

0 回答 0