Example usage for org.apache.commons.net.ftp FTPClient site

List of usage examples for org.apache.commons.net.ftp FTPClient site

Introduction

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

Prototype

public int site(String parameters) throws IOException 

Source Link

Document

A convenience method to send the FTP SITE command to the server, receive the reply, and return the reply code.

Usage

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

/**
 * FTP????/*www  .  j  a  v  a 2 s .c  o  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);
}