Example usage for org.apache.commons.net.ftp FTPReply SERVICE_NOT_AVAILABLE

List of usage examples for org.apache.commons.net.ftp FTPReply SERVICE_NOT_AVAILABLE

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPReply SERVICE_NOT_AVAILABLE.

Prototype

int SERVICE_NOT_AVAILABLE

To view the source code for org.apache.commons.net.ftp FTPReply SERVICE_NOT_AVAILABLE.

Click Source Link

Usage

From source file:ch.cyberduck.core.ftp.FTPExceptionMappingService.java

private BackgroundException handle(final FTPException e, final StringBuilder buffer) {
    final int status = e.getCode();
    switch (status) {
    case FTPReply.INSUFFICIENT_STORAGE:
    case FTPReply.STORAGE_ALLOCATION_EXCEEDED:
        return new QuotaException(buffer.toString(), e);
    case FTPReply.NOT_LOGGED_IN:
        return new LoginFailureException(buffer.toString(), e);
    case FTPReply.FAILED_SECURITY_CHECK:
    case FTPReply.DENIED_FOR_POLICY_REASONS:
    case FTPReply.NEED_ACCOUNT:
    case FTPReply.NEED_ACCOUNT_FOR_STORING_FILES:
    case FTPReply.FILE_NAME_NOT_ALLOWED:
    case FTPReply.ACTION_ABORTED:
        return new AccessDeniedException(buffer.toString(), e);
    case FTPReply.UNAVAILABLE_RESOURCE:
    case FTPReply.FILE_UNAVAILABLE:
        // Requested action not taken. File unavailable (e.g., file not found, no access)
        return new NotfoundException(buffer.toString(), e);
    case FTPReply.SERVICE_NOT_AVAILABLE:
        return new ConnectionRefusedException(buffer.toString(), e);
    }// ww  w . jav  a  2s.c o  m
    return new InteroperabilityException(buffer.toString(), e);
}

From source file:de.thischwa.pmcms.tool.connection.ftp.FtpConnectionManager.java

private void checkReply() {
    int replyCode = ftpClient.getReplyCode();

    // close connection, if dropped, so that isConnected() return false
    if (replyCode == FTPReply.SERVICE_NOT_AVAILABLE)
        close();//  ww  w  .j av  a 2 s  .  co  m

    logger.debug("[FTP] " + ftpClient.getReplyString());

    // throw exceptions depending on the replyCode, if is not positiv
    if (!FTPReply.isPositiveCompletion(replyCode)) {
        if (replyCode == FTPReply.CODE_503 || replyCode == FTPReply.NEED_PASSWORD
                || replyCode == FTPReply.NOT_LOGGED_IN)
            throw new ConnectionAuthentificationException(ftpClient.getReplyString());
        else
            throw new ConnectionRunningException(ftpClient.getReplyString());
    }
}

From source file:com.atomicleopard.thundr.ftp.commons.FTP.java

private void __getReply(boolean reportReply) throws IOException {
    int length;//w  ww  .  j a  va2  s. co m

    _newReplyString = true;
    _replyLines.clear();

    String line = _controlInput_.readLine();

    if (line == null) {
        throw new FTPConnectionClosedException("Connection closed without indication.");
    }

    // In case we run into an anomaly we don't want fatal index exceptions
    // to be thrown.
    length = line.length();
    if (length < REPLY_CODE_LEN) {
        throw new MalformedServerReplyException("Truncated server reply: " + line);
    }

    String code = null;
    try {
        code = line.substring(0, REPLY_CODE_LEN);
        _replyCode = Integer.parseInt(code);
    } catch (NumberFormatException e) {
        throw new MalformedServerReplyException("Could not parse response code.\nServer Reply: " + line);
    }

    _replyLines.add(line);

    // Get extra lines if message continues.
    if (length > REPLY_CODE_LEN && line.charAt(REPLY_CODE_LEN) == '-') {
        do {
            line = _controlInput_.readLine();

            if (line == null) {
                throw new FTPConnectionClosedException("Connection closed without indication.");
            }

            _replyLines.add(line);

            // The length() check handles problems that could arise from readLine()
            // returning too soon after encountering a naked CR or some other
            // anomaly.
        } while (isStrictMultilineParsing() ? __strictCheck(line, code) : __lenientCheck(line));
    }

    fireReplyReceived(_replyCode, getReplyString());

    if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE) {
        throw new FTPConnectionClosedException("FTP response 421 received.  Server closed connection.");
    }
}

From source file:nl.nn.adapterframework.ftp.FTPsClient.java

private Object _readReply(InputStream in, boolean concatenateLines) throws IOException {
    // obtain the result
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));

    int replyCode = 0;
    StringBuffer reply = new StringBuffer();
    List replyList = new ArrayList();
    String line = reader.readLine();

    if (line == null)
        throw new FTPConnectionClosedException("Connection closed without indication.");
    reply.append(line).append("\n");
    replyList.add(line);//from www.j av a 2 s  .co m

    // In case we run into an anomaly we don't want fatal index exceptions
    // to be thrown.
    int length = line.length();
    if (length < 3)
        throw new MalformedServerReplyException("Truncated server reply: " + line);

    try {
        String code = line.substring(0, 3);
        replyCode = Integer.parseInt(code);
    } catch (NumberFormatException e) {
        MalformedServerReplyException mfre = new MalformedServerReplyException(
                "Could not parse response code.\nServer Reply [" + line + "]");
        mfre.initCause(e);
        throw mfre;
    }

    // Get extra lines if message continues.
    if (length > 3 && line.charAt(3) == '-') {
        do {
            line = reader.readLine();
            if (line == null)
                throw new FTPConnectionClosedException(
                        "Connection closed without indication after having read [" + reply.toString() + "]");

            reply.append(line).append("\n");
            replyList.add(line);
        } while (!(line.length() >= 4 && line.charAt(3) != '-' && Character.isDigit(line.charAt(0))));
    }

    if (replyCode == FTPReply.SERVICE_NOT_AVAILABLE)
        throw new FTPConnectionClosedException("FTP response 421 received. Server closed connection.");

    if (!FTPReply.isPositiveCompletion(replyCode))
        throw new IOException("Exception while sending command \n" + reply.toString());

    log.debug("_readReply [" + reply.toString() + "]");

    if (concatenateLines) {
        return reply.toString();
    }
    return (String[]) replyList.toArray(new String[0]);
}