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

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

Introduction

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

Prototype

public int getBufferSize() 

Source Link

Document

Retrieve the current internal buffer size for buffered data streams.

Usage

From source file:FTP.Uploader.java

public void uploadFile(String filename) throws IOException {
    FTPClient ftpclient = new FTPClient();
    FileInputStream fis = null;/*from  w  ww . ja va2  s.  c o  m*/
    boolean result;
    String ftpServerAddress = "shamalmahesh.net78.net";
    String userName = "a9959679";
    String password = "9P3IckDo";

    try {
        ftpclient.connect(ftpServerAddress);
        result = ftpclient.login(userName, password);

        if (result == true) {
            System.out.println("Logged in Successfully !");
        } else {
            System.out.println("Login Fail!");
            return;
        }
        ftpclient.enterLocalPassiveMode();
        ftpclient.setFileType(FTP.BINARY_FILE_TYPE);

        ftpclient.changeWorkingDirectory("/public_html/testing");

        //            File file = new File("D:/jpg/wq.jpg");
        File file = new File(filename);
        String testName = file.getName();
        fis = new FileInputStream(file);
        System.out.println(ftpclient.getBufferSize());
        // Upload file to the ftp server
        result = ftpclient.storeFile(testName, fis);
        if (result == true) {
            System.out.println("File is uploaded successfully");
        } else {
            System.out.println("File uploading failed");
        }
        ftpclient.logout();
    } catch (FTPConnectionClosedException e) {
        e.printStackTrace();
    } finally {
        try {
            ftpclient.disconnect();
        } catch (FTPConnectionClosedException e) {
            System.out.println(e);
        }
    }
}

From source file:uk.ac.bbsrc.tgac.miso.core.util.TransmissionUtils.java

public static boolean ftpPutListen(FTPClient ftp, String path, File file, boolean autoLogout, boolean autoMkdir,
        CopyStreamListener listener) throws IOException {
    boolean error = false;
    FileInputStream fis = null;/*  www.j  ava 2  s . c  om*/

    log.info("ftpPutListen has been called for file:" + file.getName());
    try {
        if (ftp == null || !ftp.isConnected()) {
            error = true;
            throw new IOException(
                    "FTP client isn't connected. Please supply a client that has connected to the host.");
        }

        if (path != null) {
            if (autoMkdir) {
                if (!ftp.makeDirectory(path)) {
                    error = true;
                    throw new IOException("Cannot create desired path on the server.");
                }
            }
            log.info("Working dir =" + ftp.printWorkingDirectory());
            if (!ftp.changeWorkingDirectory(path)) {
                error = true;
                throw new IOException("Desired path does not exist on the server");
            }
        }

        fis = new FileInputStream(file);

        OutputStream ops = new BufferedOutputStream(ftp.storeFileStream(file.getName()), ftp.getBufferSize());

        log.info("TransmissionUtils putListen: FTP server responded: " + ftp.getReplyString());

        copyStream(fis, ops, ftp.getBufferSize(), file.length(), listener);

        ops.close();
        fis.close();
        log.info("TransmissionUtils putListen: FTP server responded: " + ftp.getReplyString());

        if (autoLogout) {
            ftp.logout();
        }
    } catch (IOException e) {
        error = true;
        log.error("ftp put listen", e);
    } finally {
        try {
            log.info("TransmissionUtils putListen:finally: " + ftp.getReplyString());
            if (fis != null) {
                fis.close();
            }

            if (autoLogout) {
                if (ftp != null && ftp.isConnected()) {
                    ftp.disconnect();
                }
            }
        } catch (IOException ioe) {
            log.error("ftp put listen close", ioe);
        }
    }

    // return inverse error boolean, just to make downstream conditionals easier
    log.info("result of transmissionutils.putListen:", !error);
    return !error;

}