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

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

Introduction

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

Prototype

public boolean setFileType(int fileType, int formatOrByteSize) throws IOException 

Source Link

Document

Sets the file type to be transferred and the format.

Usage

From source file:it.zero11.acme.example.FTPChallengeListener.java

private boolean createChallengeFiles(String token, String challengeBody) {
    boolean success = false;
    FTPClient ftp = new FTPClient();
    try {/*from   w  ww.j a va2  s  . c  o m*/
        ftp.connect(host);
        if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
            ftp.disconnect();
            return false;
        }

        ftp.login(username, password);
        ftp.changeWorkingDirectory(webroot);
        ftp.makeDirectory(".well-known");
        ftp.changeWorkingDirectory(".well-known");
        ftp.makeDirectory("acme-challenge");
        ftp.changeWorkingDirectory("acme-challenge");
        ftp.enterLocalPassiveMode();
        ftp.setFileType(FTPClient.BINARY_FILE_TYPE, FTPClient.BINARY_FILE_TYPE);
        ftp.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
        success = ftp.storeFile(token, new ByteArrayInputStream(challengeBody.getBytes()));
        if (!success)
            System.err.println("FTP error uploading file: " + ftp.getReplyCode() + ": " + ftp.getReplyString());
        ftp.logout();
    } catch (IOException e) {
        throw new AcmeException(e);
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException ioe) {
            }
        }
    }

    return success;
}

From source file:com.cisco.dvbu.ps.utils.net.FtpFile.java

public void ftpFile(String fileName) throws CustomProcedureException, SQLException {

    // new ftp client
    FTPClient ftp = new FTPClient();
    OutputStream output = null;/* www  .j av  a 2s  . co  m*/

    success = false;
    try {
        //try to connect
        ftp.connect(hostIp);

        //login to server
        if (!ftp.login(userId, userPass)) {
            ftp.logout();
            qenv.log(LOG_ERROR, "Ftp server refused connection user/password incorrect.");
        }
        int reply = ftp.getReplyCode();

        //FTPReply stores a set of constants for FTP Reply codes
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            qenv.log(LOG_ERROR, "Ftp server refused connection.");
        }

        //enter passive mode
        ftp.setFileType(FTPClient.BINARY_FILE_TYPE, FTPClient.BINARY_FILE_TYPE);
        ftp.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();

        //get system name
        //System.out.println("Remote system is " + ftp.getSystemType());

        //change current directory
        ftp.changeWorkingDirectory(ftpDirName);
        System.out.println("Current directory is " + ftp.printWorkingDirectory());
        System.out.println("File is " + fileName);

        output = new FileOutputStream(dirName + "/" + fileName);

        //get the file from the remote system
        success = ftp.retrieveFile(fileName, output);

        //close output stream
        output.close();

    } catch (IOException ex) {
        throw new CustomProcedureException("Error in CJP " + getName() + ": " + ex.toString());
    }
}

From source file:uk.sipperfly.utils.FTPUtil.java

public static void reconnect() throws SocketException, IOException {
    FTPClient ftpClient = new FTPClient();
    ftpClient.setControlEncoding("UTF-8");
    ftpClient.connect(host, port);/*from   w  w w .j  a v a2  s .c  om*/
    ftpClient.login(username, password);
    if (mode.equalsIgnoreCase("passive")) {
        ftpClient.enterLocalPassiveMode();
    } else if (mode.equalsIgnoreCase("active")) {
        ftpClient.enterLocalActiveMode();
    }
    int reply = ftpClient.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        Logger.getLogger(GACOM).log(Level.INFO, "FTP Login: ".concat(ftpClient.getReplyString()));
        ftpClient.disconnect();
    }
    ftpClient.setKeepAlive(true);
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE);
    ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
    ftpClient.setControlKeepAliveTimeout(300);
    //      ftpClient.sendSiteCommand("RECFM=FB");
    //      ftpClient.sendSiteCommand("LRECL=2000");
    //      ftpClient.sendSiteCommand("BLKSIZE=27000");
    //      ftpClient.sendSiteCommand("CY");
    //      ftpClient.sendSiteCommand("PRI= 50");
    //      ftpClient.sendSiteCommand("SEC=25");

    //      ftpClient.sendSiteCommand("RECFM=FB");
    //      ftpClient.sendSiteCommand("LRECL=2000");
    //      ftpClient.sendSiteCommand("BLOCKSIZE=27000");
    //      ftpClient.sendSiteCommand("SPACE=(CYL,(30,300),RLSE)"); 
    //      ftpClient.sendSiteCommand("TR");
    //      ftpClient.sendSiteCommand("PRI=450");
    //      ftpClient.sendSiteCommand("SEC=4500");

    Logger.getLogger(GACOM).log(Level.INFO, "Reconnected FTP");
    System.out.println("reconnected");
}