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

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

Introduction

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

Prototype

int FILE_UNAVAILABLE

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

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);
    }/*  www . ja va 2 s .  co m*/
    return new InteroperabilityException(buffer.toString(), e);
}

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

@Override
public void createDirectory(final String path) throws IOException {
    LOGGER.debug("createDirectory (path : {})", path);
    executionHandler(new Callable<Void>() {
        @Override//from  w w w  .j ava  2 s.  c  o m
        public Void call() throws Exception {
            int replyCode = ftpClient.mkd(path);
            String replyText = ftpClient.getReplyString();
            if (!FTPReply.isPositiveCompletion(replyCode)) {
                // this replyText code is set when file already exists on the server
                if (FTPReply.FILE_UNAVAILABLE == replyCode)
                    throw new FileAlreadyExistsException(path);
                else
                    LOGGER.warn("Unexpected Reply (Code: {}, Text: '{}'", replyCode, replyText);
            }
            return null;
        }
    });
}

From source file:org.limy.common.util.FtpUtils.java

/**
 * FTP????//from   w  ww  .  j  a v  a2s .co m
 * @param client FTP
 * @param rootPath 
 * @param relativePath ??
 * @param contents 
 * @return ????
 * @throws IOException I/O
 */
public static boolean uploadFileFtp(FTPClient client, String rootPath, String relativePath,
        InputStream contents) throws IOException {

    int cwd = client.cwd(rootPath);
    if (cwd == FTPReply.FILE_UNAVAILABLE) {
        // ???????
        if (rootPath.startsWith("/")) {
            mkdirsAbsolute(client, rootPath);
        } else {
            mkdirs(client, rootPath);
        }
    }

    LOG.debug("uploadFileFtp : " + rootPath + " ->" + relativePath);
    String targetDir = UrlUtils.getParent(relativePath);
    if (targetDir.startsWith("/")) {
        mkdirsAbsolute(client, targetDir);
    } else {
        mkdirs(client, targetDir);
    }
    client.cwd(rootPath);
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.site("chmod 664 " + relativePath);
    return client.storeFile(relativePath, contents);
}

From source file:org.limy.common.util.FtpUtils.java

/**
 * ???????/*ww  w.  ja  v  a2 s  .  c om*/
 * @param client FTP
 * @param remotePath ??
 * @throws IOException I/O
 */
private static void mkdirs(FTPClient client, String remotePath) throws IOException {
    if (client.cwd(remotePath) == FTPReply.FILE_UNAVAILABLE) {
        LOG.debug("Mkdir(ftp) : " + remotePath);

        StringTokenizer tokenizer = new StringTokenizer(remotePath, "/");
        StringBuilder subDir = new StringBuilder();
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            subDir.append(token);
            client.mkd(subDir.toString());
            subDir.append("/");
        }
    }
}

From source file:org.limy.common.util.FtpUtils.java

/**
 * ???????/*from  ww w. j  av  a2s. com*/
 * @param client FTP
 * @param absolutePath 
 * @throws IOException I/O
 */
private static void mkdirsAbsolute(FTPClient client, String absolutePath) throws IOException {
    String baseDir = absolutePath;
    while (client.cwd(baseDir) == FTPReply.FILE_UNAVAILABLE) {
        if (baseDir.lastIndexOf('/') < 0) {
            break;
        }
        baseDir = baseDir.substring(0, baseDir.lastIndexOf('/'));
    }
    if (baseDir.length() == absolutePath.length()) {
        return;
    }
    int pos = absolutePath.indexOf('/', baseDir.length() + 1);
    client.mkd(absolutePath.substring(0, pos));
    mkdirsAbsolute(client, absolutePath);
}