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

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

Introduction

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

Prototype

int FILE_ACTION_NOT_TAKEN

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

Click Source Link

Usage

From source file:at.beris.virtualfile.client.ftp.FtpClient.java

@Override
public boolean exists(final String path) throws IOException {
    LOGGER.debug("exists (path : {})", path);
    Boolean exists = executionHandler(new Callable<Boolean>() {
        @Override/*from  w w w.  j  av  a 2s .com*/
        public Boolean call() throws Exception {

            int replyCode = ftpClient.stat(path);
            String replyText = ftpClient.getReplyString();
            if (!FTPReply.isPositiveCompletion(replyCode)) {
                // this replyText code is set when file doesn't exist on the server
                if (FTPReply.FILE_ACTION_NOT_TAKEN == replyCode)
                    return false;
                else {
                    LOGGER.warn("Unexpected Reply (Code: {}, Text: '{}'", replyCode, replyText);
                }
            }

            String[] replyTextParts = replyText.split("\n");
            if (replyTextParts.length <= 2) {
                if (ftpClient.changeWorkingDirectory(path))
                    ftpClient.changeToParentDirectory();
                else
                    return false;
            }
            return true;
        }
    });
    LOGGER.debug("Returns: {}", exists);
    return exists;
}