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

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

Introduction

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

Prototype

public FTPClient() 

Source Link

Document

Default FTPClient constructor.

Usage

From source file:com.adaptris.core.ftp.ClientSettingsTest.java

@Test
public void testPreConnectSettings_FTP() {
    FTPClient client = new FTPClient();
    preConnectSettings(client, FTP.values(), createFtpSettings());
    assertTrue(client.isUseEPSVwithIPv4());
    assertTrue(client.isStrictReplyParsing());
    assertTrue(client.isStrictMultilineParsing());
    assertFalse(client.isRemoteVerificationEnabled());
    assertTrue(client.getListHiddenFiles());
    assertTrue(client.getAutodetectUTF8());
}

From source file:cn.zhuqi.mavenssh.web.util.FtpUtil.java

public FtpUtil() {
    ftp = new FTPClient();
    is_connected = false;
    ftp.setDefaultTimeout(30 * 1000);
    ftp.setConnectTimeout(30 * 1000);
    ftp.setDataTimeout(300 * 1000);
}

From source file:com.zxy.commons.net.ftp.FtpUtils.java

/**
 * FTP handle//from  w  w w. ja v  a  2  s .  c o m
 * 
 * @param <T> return object type
 * @param ftpConfig ftp config
 * @param callback ftp callback
 * @return value
*/
public static <T> T ftpHandle(FtpConfig ftpConfig, FtpCallback<T> callback) {
    FTPClient client = null;
    if (ftpConfig.isFtps() && ftpConfig.getSslContext() != null) {
        client = new FTPSClient(ftpConfig.getSslContext());
    } else if (ftpConfig.isFtps()) {
        client = new FTPSClient();
    } else {
        client = new FTPClient();
    }

    client.configure(ftpConfig.getFtpClientConfig());
    try {
        //            client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        client.connect(ftpConfig.getHost(), ftpConfig.getPort());
        client.setConnectTimeout(ftpConfig.getConnectTimeoutMs());
        client.setControlKeepAliveTimeout(ftpConfig.getKeepAliveTimeoutSeconds());
        if (!Strings.isNullOrEmpty(ftpConfig.getUsername())) {
            client.login(ftpConfig.getUsername(), ftpConfig.getPassword());
        }
        LOGGER.trace("Connected to {}, reply: {}", ftpConfig.getHost(), client.getReplyString());

        // After connection attempt, you should check the reply code to verify success.
        int reply = client.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            client.disconnect();
            throw new NetException("FTP server refused connection.");
        }
        return callback.process(client);
    } catch (Exception e) {
        throw new NetException(e);
    } finally {
        if (client.isConnected()) {
            try {
                client.logout();
            } catch (IOException ioe) {
                LOGGER.warn(ioe.getMessage());
            }
            try {
                client.disconnect();
            } catch (IOException ioe) {
                LOGGER.warn(ioe.getMessage());
            }
        }
    }
}

From source file:de.idos.updates.lookup.FtpLookup.java

private Version findLatestVersion() throws IOException {
    FTPClient ftpClient = new FTPClient();
    ftpClient.connect(inetAddress);/*from www.  java  2  s.c om*/
    ftpClient.enterLocalPassiveMode();

    if (login != null) {
        ftpClient.login(login, null);
    }

    if (workingDir != null) {
        ftpClient.changeWorkingDirectory(workingDir);
    }

    FTPFile[] availableVersionsDirs = ftpClient.listDirectories();
    List<String> strings = new ArrayList<String>();
    for (FTPFile ftpFile : availableVersionsDirs) {
        strings.add(ftpFile.getName());
    }

    List<Version> versions = new VersionFactory().createVersionsFromStrings(strings);
    return new VersionFinder().findLatestVersion(versions);
}

From source file:VentanaPrincipal.java

/**
 * Creates new form VentanaPrincipal
 */
public VentanaPrincipal() {
    initComponents();
    cliente = new FTPClient();
}

From source file:ftp.FTPHelper.java

public void connect() throws IOException {
    if (isFtps()) {
        ftp = new FTPSClient();

    } else {/*from   ww w  .j  a va2 s.c o m*/

        ftp = new FTPClient();
        ftp.connect(url);
        ftp.login(username, password);

    }

}

From source file:atualizador.Atualizador.java

private static void FTPDownload(String fileName, String DiretorioFTP)
        throws IOException, FileNotFoundException {
    FTPClient client = new FTPClient();
    FileOutputStream fos = null;//from w ww  .  java 2  s .  co  m

    client.connect("plutao.telemar");
    client.login("usrcorj", "usr341!tg");

    String filename = fileName;
    fos = new FileOutputStream(filename);

    client.changeWorkingDirectory(DiretorioFTP);
    client.retrieveFile(filename, fos);
    fos.close();
    client.disconnect();
}

From source file:ftp_server.FileUpload.java

public void uploading() {
    FTPClient client = new FTPClient();
    FileInputStream fis = null;//  w w  w. j av  a  2 s .  c o m
    try {
        client.connect("shamalmahesh.net78.net");
        client.login("a9959679", "9P3IckDo");
        client.setFileType(FTP.BINARY_FILE_TYPE);
        int reply = client.getReplyCode();
        if (FTPReply.isPositiveCompletion(reply)) {
            System.out.println("Uploading....");
        } else {
            System.out.println("Failed connect to the server!");
        }
        //            String filename = "DownloadedLook1.txt";
        String path = "D:\\jpg\\";
        //            String filename = "1.jpg";
        String filename = "appearance.jpg";
        System.out.println(path + filename);
        fis = new FileInputStream(path + filename);
        System.out.println(fis.toString());
        boolean status = client.storeFile("/public_html/testing/" + filename, fis);
        System.out.println("Status : " + status);
        System.out.println("Done!");
        client.logout();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            client.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.baifendian.swordfish.common.job.struct.datasource.FtpDatasource.java

@Override
public void isConnectable() throws Exception {
    FTPClient ftpClient = new FTPClient();
    ftpClient.connect(this.host, this.port);
    if (!ftpClient.login(this.user, this.password)) {
        throw new Exception("wrong user name or password");
    }/*w  ww.j  a  va2 s.co  m*/
}

From source file:com.metamolecular.pubcouch.pubchem.Archive.java

public Archive() {
    client = new FTPClient();
}