/** * Checks if the given IOException corresponds to a low-level socket exception, and if that is the case, * closes the connection so that {@link #isConnected()} returns false. * All IOException raised by FTPClient should be checked by this method so that socket errors are properly detected. */ private void checkSocketException(IOException e) { if(((e instanceof FTPConnectionClosedException) || (e instanceof SocketException) || (e instanceof SocketTimeoutException)) && isConnected()) { LOGGER.info("socket exception detected, closing connection", e); closeConnection(); } }
/** * Checks the last server reply code and throws an IOException if the code doesn't correspond to a positive * FTP reply: * * <ul> * <li>If the reply is a credentials error (lack of permissions or not logged in), an {@link AuthException} * is thrown. For all other error codes, an IOException is thrown with the server reply message. * <li>If the reply code is FTPReply.SERVICE_NOT_AVAILABLE (connection dropped prematurely), the connection * will be closed before an IOException with the server reply message is thrown. * </ul> * * <p>If the reply is a positive one (not an error error), this method does nothing. */ private void checkServerReply() throws IOException, AuthException { // Check that connection went ok int replyCode = ftpClient.getReplyCode(); LOGGER.trace("server reply="+ftpClient.getReplyString()); // Close connection if the connection dropped prematurely so that isConnected() returns false if(replyCode==FTPReply.SERVICE_NOT_AVAILABLE) closeConnection(); // If not, throw an exception using the reply string if(!FTPReply.isPositiveCompletion(replyCode)) { if(replyCode==FTPReply.BAD_COMMAND_SEQUENCE || replyCode==FTPReply.NEED_PASSWORD || replyCode==FTPReply.NOT_LOGGED_IN) throwAuthException(ftpClient.getReplyString()); else throw new IOException(ftpClient.getReplyString()); } }