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

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

Introduction

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

Prototype

public int pasv() throws IOException 

Source Link

Document

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

Usage

From source file:de.l3s.dlg.ncbikraken.ftp.NcbiFTPClient.java

public static void getMedline(MedlineFileType type) {
    FileOutputStream out = null;// ww w .j  av a  2 s.  co  m
    FTPClient ftp = new FTPClient();
    try {
        // Connection String
        LOGGER.info("Connecting to FTP server " + SERVER_NAME);
        ftp.connect(SERVER_NAME);
        ftp.login("anonymous", "");
        ftp.cwd(BASELINE_PATH);
        ftp.cwd(type.getServerPath());

        try {
            ftp.pasv();
        } catch (IOException e) {
            LOGGER.error(
                    "Can not access the passive mode. Maybe a problem with your (Windows) firewall. Just try to run as administrator: \nnetsh advfirewall set global StatefulFTP disable");
            return;
        }

        for (FTPFile file : ftp.listFiles()) {
            if (file.isFile()) {
                File meshF = new File(file.getName());
                LOGGER.debug("Downloading file: " + SERVER_NAME + ":" + BASELINE_PATH + "/"
                        + type.getServerPath() + "/" + meshF.getName());
                out = new FileOutputStream(Configuration.INSTANCE.getMedlineDir() + File.separator + meshF);
                ftp.retrieveFile(meshF.getName(), out);
                out.flush();
                out.close();
            }
        }

    } catch (IOException ioe) {
        LOGGER.error(ioe.getMessage());

    } finally {
        IOUtils.closeQuietly(out);
        try {
            ftp.disconnect();
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
    }

}

From source file:org.alinous.ftp.FtpManager.java

public boolean login(String sessionId, String username, String password) throws IOException {
    FTPClient ftp = this.instances.get(sessionId).getFtp();

    boolean result = ftp.login(username, password);

    if (!result) {
        this.instances.remove(sessionId);
    }/*from w  w w.ja  va 2 s  . com*/

    ftp.pasv();
    printFtpReply(ftp);

    return result;
}