/** Abort the current transfer */ private void abortTransfer() { // logger.debug("Will abort transfer and write: ", write); FtpFile file = null; FtpTransfer current = null; try { current = getExecutingFtpTransfer(); file = current.getFtpFile(); file.abortFile(); } catch (FtpNoTransferException e) { logger.warn("Abort problem", e); } catch (FtpNoFileException e) { } catch (CommandAbstractException e) { logger.warn("Abort problem", e); } if (current != null) { current.setStatus(false); } endDataConnection(); session.setReplyCode( ReplyCode.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "Transfer aborted for " + (current == null ? "Unknown command" : current.toString())); if (current != null) { if (!FtpCommandCode.isListLikeCommand(current.getCommand())) { try { session.getBusinessHandler().afterTransferDoneBeforeAnswer(current); } catch (CommandAbstractException e) { session.setReplyCode(e); } } } finalizeExecution(); }
/** Finish correctly a transfer */ private void closeTransfer() { // logger.debug("Will close transfer and write: {}", write); FtpFile file = null; FtpTransfer current = null; try { current = getExecutingFtpTransfer(); file = current.getFtpFile(); file.closeFile(); } catch (FtpNoTransferException e) { logger.warn("Close problem", e); } catch (FtpNoFileException e) { } catch (CommandAbstractException e) { logger.warn("Close problem", e); } if (current != null) { current.setStatus(true); } if (session.getDataConn().isStreamFile()) { endDataConnection(); } session.setReplyCode( ReplyCode.REPLY_226_CLOSING_DATA_CONNECTION, "Transfer complete for " + (current == null ? "Unknown command" : current.toString())); if (current != null) { if (!FtpCommandCode.isListLikeCommand(current.getCommand())) { try { session.getBusinessHandler().afterTransferDoneBeforeAnswer(current); } catch (CommandAbstractException e) { session.setReplyCode(e); } } else { // Special wait to prevent fast LIST following by STOR or RETR command try { Thread.sleep(FtpInternalConfiguration.RETRYINMS); } catch (InterruptedException e) { } } } finalizeExecution(); }