Example usage for org.apache.commons.net.ftp FTPConnectionClosedException FTPConnectionClosedException

List of usage examples for org.apache.commons.net.ftp FTPConnectionClosedException FTPConnectionClosedException

Introduction

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

Prototype

public FTPConnectionClosedException(String message) 

Source Link

Document

Constructs a FTPConnectionClosedException with a specified message.

Usage

From source file:com.myJava.file.driver.remote.ftp.SecuredSocketFactory.java

private void readReply(Socket socket) throws IOException {
    // Read response
    BufferedReader in = new BufferedReader(
            new InputStreamReader(socket.getInputStream(), client.getControlEncoding()));
    String line = in.readLine();//from  w  ww. jav a  2 s  .c o m
    StringBuffer sb = new StringBuffer(line);
    int length = line.length();
    if (length > 3 && line.charAt(3) == '-') {
        do {
            line = in.readLine();
            sb.append(" / ").append(line);

            if (line == null) {
                throw new FTPConnectionClosedException("Connection closed without indication.");
            }
        } while (!(line.length() >= 4 && line.charAt(3) != '-' && Character.isDigit(line.charAt(0))));
    }
    Logger.defaultLogger().info("Received FTP server response : " + sb.toString());
}

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

private void __getReply(boolean reportReply) throws IOException {
    int length;//from   w w  w  .  j av  a 2  s  .  c  o 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:com.atomicleopard.thundr.ftp.commons.FTP.java

private void __send(String message) throws IOException, FTPConnectionClosedException, SocketException {
    try {//w w  w . j a  v a 2 s. c  o m
        _controlOutput_.write(message);
        _controlOutput_.flush();
    } catch (SocketException e) {
        if (!isConnected()) {
            throw new FTPConnectionClosedException("Connection unexpectedly closed.");
        } else {
            throw e;
        }
    }
}

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  w  ww  .jav  a  2s  . c o  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]);
}