Пример #1
0
 /** 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();
 }
Пример #2
0
 /** 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();
 }
Пример #3
0
 /**
  * Called when a transfer is finished from setEndOfTransfer
  *
  * @return True if it was already called before
  * @throws FtpNoTransferException
  */
 private boolean checkFtpTransferStatus() throws FtpNoTransferException {
   if (isCheckAlreadyCalled) {
     logger.warn("Check: ALREADY CALLED");
     return true;
   }
   if (isExecutingCommandFinished) {
     // already done
     logger.warn("Check: already Finished");
     if (commandFinishing != null) {
       commandFinishing.cancel();
     }
     throw new FtpNoTransferException("No transfer running");
   }
   if (!isDataNetworkHandlerReady) {
     // already done
     logger.warn("Check: already DNH not ready");
     throw new FtpNoTransferException("No connection");
   }
   isCheckAlreadyCalled = true;
   FtpTransfer executedTransfer = getExecutingFtpTransfer();
   // logger.debug("Check: command {}", executedTransfer.getCommand());
   // DNH is ready and Transfer is running
   if (FtpCommandCode.isListLikeCommand(executedTransfer.getCommand())) {
     if (executedTransfer.getStatus()) {
       // Special status for List Like command
       // logger.debug("Check: List OK");
       closeTransfer();
       return false;
     }
     // logger.debug("Check: List Ko");
     abortTransfer();
     return false;
   } else if (FtpCommandCode.isRetrLikeCommand(executedTransfer.getCommand())) {
     FtpFile file = null;
     try {
       file = executedTransfer.getFtpFile();
     } catch (FtpNoFileException e) {
       // logger.debug("Check: Retr no FtpFile for Retr");
       abortTransfer();
       return false;
     }
     try {
       if (file.isInReading()) {
         logger.debug("Check: Retr FtpFile still in reading KO");
         abortTransfer();
       } else {
         logger.debug("Check: Retr FtpFile no more in reading OK");
         closeTransfer();
       }
     } catch (CommandAbstractException e) {
       logger.warn("Retr Test is in Reading problem", e);
       closeTransfer();
     }
     return false;
   } else if (FtpCommandCode.isStoreLikeCommand(executedTransfer.getCommand())) {
     // logger.debug("Check: Store OK");
     closeTransfer();
     return false;
   } else {
     logger.warn("Check: Unknown command");
     abortTransfer();
   }
   return false;
 }