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

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

Introduction

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

Prototype

int PASSIVE_LOCAL_DATA_CONNECTION_MODE

To view the source code for org.apache.commons.net.ftp FTPClient PASSIVE_LOCAL_DATA_CONNECTION_MODE.

Click Source Link

Document

A constant indicating the FTP session is expecting all transfers to occur between the client (local) and server and that the server is in passive mode, requiring the client to connect to the server's data port to initiate a transfer.

Usage

From source file:com.apress.prospringintegration.ftp.FtpConfiguration.java

@Bean
public DefaultFtpSessionFactory ftpClientFactory() {
    DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory();
    ftpSessionFactory.setHost(host);//from  ww  w  .  j  a v  a  2 s.  c  o m
    ftpSessionFactory.setUsername(username);
    ftpSessionFactory.setPassword(password);
    ftpSessionFactory.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
    return ftpSessionFactory;
}

From source file:lucee.runtime.net.ftp.FTPWrap.java

static void setConnectionSettings(FTPClient client, FTPConnection conn) {
    if (client == null)
        return;/*  www  .  ja va2  s. c o  m*/

    // timeout
    client.setDataTimeout(conn.getTimeout() * 1000);
    try {
        client.setSoTimeout(conn.getTimeout() * 1000);
    } catch (Throwable t) {
    }

    // passive/active Mode
    int mode = client.getDataConnectionMode();
    if (conn.isPassive()) {
        if (FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE != mode)
            client.enterLocalPassiveMode();
    } else {
        if (FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE != mode)
            client.enterLocalActiveMode();
    }
}

From source file:com.brightcove.uploader.input.Batch.java

public ArrayList<String> createVideos(IngestFile[] pVideoFiles, Account pAccount, Environment pEnvironment,
        boolean waitForPickup)
        throws BadEnvironmentException, MediaAPIError, JSONException, URISyntaxException, IOException {

    String manifest = constructManifest(pVideoFiles, pAccount, pEnvironment);
    String delManifest = constructCleanupManifest(pVideoFiles, pAccount, pEnvironment);

    String ftphost = pEnvironment.getFTPServer();
    String ftpRootDir = pEnvironment.getFTPRootDir();
    String ftpuser = pAccount.getFtpLogin();
    String ftppass = pAccount.getFtpPassword();

    FTPHelperBuilder ftpHB = new FTPHelperBuilder(ftphost, ftpuser, ftppass,
            FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
    FTPHelper ftpH = ftpHB.createFTPHelper();
    boolean loggedin = ftpH.connect();
    mLog.info("connected: " + loggedin + " to " + ftphost);
    ArrayList<String> refids = new ArrayList<String>();
    for (IngestFile video : pVideoFiles) {
        ftpH.put(ftpRootDir, video.getUniqueID() + video.getFile().getName(), video.getFile());
        refids.add("title-" + video.getUniqueID());
    }/*from   w  w  w .  j  a  va  2s .c o  m*/
    String manifestName = System.currentTimeMillis() + "batchSystemTest.xml";
    ftpH.put(ftpRootDir, manifestName, new ByteArrayInputStream(manifest.getBytes()));
    mLog.info("Uploading " + manifestName + " manifest");
    String delManifestName = System.currentTimeMillis() + "batchSystemTestCleanup.xml.del";
    ftpH.put(ftpRootDir, delManifestName, new ByteArrayInputStream(delManifest.getBytes()));

    if (waitForPickup) {
    }
    ftpH.disconnect();

    return refids;
}

From source file:com.brightcove.zartan.encoding.test.ZencodeTest.java

public void testZencode() throws Throwable {
    VerifiableSerializer vser = new VerifiableSerializer();
    ZencodeAPI zapi = new ZencodeAPI();
    User u = new User("storpey@brightcove.com", "Password!", true);
    List<Credentials> creds = new ArrayList<Credentials>();
    creds.add(new ZencoderCredentials("716a8085f2094a65d8688d06d2637364"));
    Account acc = new Account(u, 123l, creds);
    AccountHelper ah = new AccountHelper();
    ArrayList<VideoFileInfo> files = getFils();
    TencodeAPI tapi = new TencodeAPI();
    User tu = new User("storpey@brightcove.com", "Password!", true);

    Account tacc = new Account(u, 123l, null);
    TranscodeEnvironment env = new TranscodeEnvironment("zen-prod", "https://app.zencoder.com/api/v2/jobs");

    TranscodeEnvironment tenv = new TranscodeEnvironment("tencode",
            "http://golftrans02.qanet.local:23080/tencode/encode/submit");
    FTPHelperBuilder ftpHB = new FTPHelperBuilder("10.1.11.139", "qa", "Passw0rd!",
            FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
    FTPHelper ftpH = ftpHB.createFTPHelper();
    for (VideoFileInfo file : files) {

        TranscodeInfo transcode = new TranscodeInfo(
                new TranscodeOptionGroup(ah.getDefaultTranscodeOptions(), "Default Transcode Options"), file);

        Verifiable vt = zapi.submitTranscode(transcode, env, acc);
        vser.addVerifiable(vt);/*from   w w w. j av  a  2s .  c  o m*/

        TranscodeInfo ttranscode = new TranscodeInfo(
                new TranscodeOptionGroup(ah.getDefaultTranscodeOptions(), "Default Transcode Options"), file);

        tapi.submitTranscode(ttranscode, tenv, tacc);
    }
    try {
        vser.serializeToFile("test.json");
    } catch (IOException e) {
        e.printStackTrace();
    }
    ArrayList<String> haveSeen = new ArrayList<String>();
    VerifiableSerializer v = VerifiableSerializer.deserializeFromFile("test.json");
    //TranscodeVerifierRunner tvr= new TranscodeVerifierRunner();
    for (Verifiable verf : v.getVerifiableList()) {
        if (verf instanceof VerifiableTranscode) {
            VerifiableTranscode tverf = (VerifiableTranscode) verf;
            TrancodeResponse response = new TrancodeResponse();
            for (TranscodedVideoFile tf : ((VerifiableTranscode) verf).getTranscodedVideoFiles()) {
                response.addTranscodedVideoFile(tf);
                String location = response.getFileLocation(tf);
                if (!haveSeen.contains(location)) {
                    String location2 = "/zencoder/output-" + tf.getMatchingRequest().getOptionId()
                            + tverf.getTranscodeInfo().getFile().getFileName() + ".mp4";
                    ftpH.connect();
                    ftpH.put("/", location2, new File(location));
                    ftpH.disconnect();
                    haveSeen.add(location);
                    System.out.println(location + " , " + location2);
                }

            }
            //tvr.runVerifiers(tverf, response);
        }
    }
    ftpH.disconnect();
}

From source file:com.brightcove.uploader.input.Batch.java

public String retranscodeVideo(IngestFile pVideoFiles, Account pAccount, Environment pEnvironment,
        String retranscodeType, IngestFile newAssetFile) throws IOException {
    String manifest = constructRetranscodeManifest(pVideoFiles, pAccount, pEnvironment, retranscodeType,
            newAssetFile);//  w ww .j  a  v  a2 s  . c o m
    String ftphost = pEnvironment.getFTPServer();
    String ftpRootDir = pEnvironment.getFTPRootDir();
    String ftpuser = pAccount.getFtpLogin();
    String ftppass = pAccount.getFtpPassword();

    FTPHelperBuilder ftpHB = new FTPHelperBuilder(ftphost, ftpuser, ftppass,
            FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
    FTPHelper ftpH = ftpHB.createFTPHelper();
    boolean loggedin = ftpH.connect();
    System.out.print(loggedin);
    if (!(newAssetFile == null)) {
        if (!newAssetFile.getFilename().isEmpty()) {
            ftpH.put(ftpRootDir, newAssetFile.getFile().getName(), newAssetFile.getFile());
        }
    }
    String manifestName = System.currentTimeMillis() + "-" + pVideoFiles.getRefId()
            + "-RetranscodebatchSystemTest.xml";
    ftpH.put(ftpRootDir, manifestName, new ByteArrayInputStream(manifest.getBytes()));
    return pVideoFiles.getRefId();

}

From source file:org.springframework.integration.ftp.session.AbstractFtpSessionFactory.java

/**
 * ACTIVE_LOCAL_DATA_CONNECTION_MODE = 0 <br>
 * A constant indicating the FTP session is expecting all transfers
 * to occur between the client (local) and server and that the server
 * should connect to the client's data port to initiate a data transfer.
 * This is the default data connection mode when and FTPClient instance
 * is created./*from  w  w  w.ja  v a 2  s.c  o  m*/
 * PASSIVE_LOCAL_DATA_CONNECTION_MODE = 2 <br>
 * A constant indicating the FTP session is expecting all transfers
 * to occur between the client (local) and server and that the server
 * is in passive mode, requiring the client to connect to the
 * server's data port to initiate a transfer.
 */
public void setClientMode(int clientMode) {
    Assert.isTrue(
            clientMode == FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE
                    || clientMode == FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE,
            "Only local modes are supported. Was: " + clientMode);
    this.clientMode = clientMode;
}

From source file:org.springframework.integration.ftp.session.AbstractFtpSessionFactory.java

/**
 * Sets the mode of the connection. Only local modes are supported.
 *//*from  www.j av a 2 s  . c om*/
private void updateClientMode(FTPClient client) {
    switch (this.clientMode) {
    case FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE:
        client.enterLocalActiveMode();
        break;
    case FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE:
        client.enterLocalPassiveMode();
        break;
    default:
        break;
    }
}

From source file:org.springframework.integration.ftp.session.SessionFactoryTests.java

@Test
public void testClientModes() throws Exception {
    DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
    Field[] fields = FTPClient.class.getDeclaredFields();
    for (Field field : fields) {
        if (field.getName().endsWith("MODE")) {
            try {
                int clientMode = field.getInt(null);
                sessionFactory.setClientMode(clientMode);
                if (!(clientMode == FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE
                        || clientMode == FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE)) {
                    fail();//  www.j av a 2s .c o  m
                }
            } catch (IllegalArgumentException e) {
                // success
            } catch (Throwable e) {
                fail();
            }
        }
    }
}