Example usage for org.apache.commons.net.ftp FTP DEFAULT_PORT

List of usage examples for org.apache.commons.net.ftp FTP DEFAULT_PORT

Introduction

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

Prototype

int DEFAULT_PORT

To view the source code for org.apache.commons.net.ftp FTP DEFAULT_PORT.

Click Source Link

Document

The default FTP control port (21).

Usage

From source file:biz.gabrys.lesscss.extended.compiler.source.FtpSource.java

/**
 * Constructs a new instance and sets URL of the source file and its encoding.
 * @param url the source file URL.//w w w.  j  a  v a  2s.  c om
 * @param encoding the source file encoding.
 * @since 2.0
 */
public FtpSource(final URL url, final String encoding) {
    this.url = url;
    port = url.getPort() != -1 ? url.getPort() : FTP.DEFAULT_PORT;
    this.encoding = encoding;
}

From source file:com.datatorrent.lib.io.AbstractFTPInputOperator.java

public AbstractFTPInputOperator() {
    super();
    port = FTP.DEFAULT_PORT;
    userName = "anonymous";
    password = "guest";
}

From source file:com.google.android.exoplayer.upstream.FtpDataSource.java

@Override
public long open(DataSpec dataSpec) throws FtpDataSourceException {
    this.dataSpec = dataSpec;
    String host = dataSpec.uri.getHost();
    int port = dataSpec.uri.getPort();
    if (port <= 0)
        port = FTP.DEFAULT_PORT;
    String filePath = dataSpec.uri.getPath();
    String userInfo = dataSpec.uri.getUserInfo();
    Log.i("ftp", "fpt login:" + dataSpec.uri.toString() + " " + dataSpec.position);
    String user = "anonymous", pass = "";

    if (userInfo != null) {
        StringTokenizer tok = new StringTokenizer(userInfo, ":@");
        if (tok.countTokens() > 0) {
            user = tok.nextToken();/*  w ww .  ja  v a2  s .  c  o m*/
            if (tok.hasMoreTokens())
                pass = tok.nextToken();
        }
    }

    try {
        long start_time = System.currentTimeMillis();
        ftpClient.connect(host, port);
        isConnect = FTPReply.isPositiveCompletion(ftpClient.getReplyCode());
        if (!isConnect)
            throw new FtpDataSourceException("connect failed.");
        Log.i("ftp", "ftp connect use:" + (System.currentTimeMillis() - start_time));

        isLogin = ftpClient.login(user, pass);
        Log.i("ftp", "ftp login use:" + (System.currentTimeMillis() - start_time));
        Log.i("ftp", "fpt login:" + user + ":" + pass + "@" + host + ":" + port + " - " + isLogin);
        if (!isLogin)
            throw new FtpDataSourceException("login failed.");

        fileSize = getFileSize(ftpClient, filePath);

        ftpClient.enterLocalPassiveMode();
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        ftpClient.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE);
        ftpClient.setRestartOffset(dataSpec.position);
        stream = ftpClient.retrieveFileStream(filePath);
        bytesRemaining = dataSpec.length == C.LENGTH_UNBOUNDED ? fileSize - dataSpec.position : dataSpec.length;
    } catch (IOException e) {
        throw new FtpDataSourceException(e);
    }

    opened = true;
    if (listener != null) {
        listener.onTransferStart();
    }
    return bytesRemaining;
}

From source file:org.apache.hadoop.fs.ftp.FTPFileSystem.java

@Override
public void initialize(URI uri, Configuration conf) throws IOException { // get
    super.initialize(uri, conf);
    // get host information from uri (overrides info in conf)
    String host = uri.getHost();/*from  w w  w .jav a 2  s.  c  o  m*/
    host = (host == null) ? conf.get("fs.ftp.host", null) : host;
    if (host == null) {
        throw new IOException("Invalid host specified");
    }
    conf.set("fs.ftp.host", host);

    // get port information from uri, (overrides info in conf)
    int port = uri.getPort();
    port = (port == -1) ? FTP.DEFAULT_PORT : port;
    conf.setInt("fs.ftp.host.port", port);

    // get user/password information from URI (overrides info in conf)
    String userAndPassword = uri.getUserInfo();
    if (userAndPassword == null) {
        userAndPassword = (conf.get("fs.ftp.user." + host, null) + ":"
                + conf.get("fs.ftp.password." + host, null));
        if (userAndPassword == null) {
            throw new IOException("Invalid user/passsword specified");
        }
    }
    String[] userPasswdInfo = userAndPassword.split(":");
    conf.set("fs.ftp.user." + host, userPasswdInfo[0]);
    if (userPasswdInfo.length > 1) {
        conf.set("fs.ftp.password." + host, userPasswdInfo[1]);
    } else {
        conf.set("fs.ftp.password." + host, null);
    }
    setConf(conf);
    this.uri = uri;
}

From source file:org.apache.hadoop.fs.ftp.FTPFileSystem.java

/**
 * Connect to the FTP server using configuration parameters *
 * //www . j av a  2 s.co  m
 * @return An FTPClient instance
 * @throws IOException
 */
private FTPClient connect() throws IOException {
    FTPClient client = null;
    Configuration conf = getConf();
    String host = conf.get("fs.ftp.host");
    int port = conf.getInt("fs.ftp.host.port", FTP.DEFAULT_PORT);
    String user = conf.get("fs.ftp.user." + host);
    String password = conf.get("fs.ftp.password." + host);
    client = new FTPClient();
    client.connect(host, port);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        throw new IOException("Server - " + host + " refused connection on port - " + port);
    } else if (client.login(user, password)) {
        client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
        client.setFileType(FTP.BINARY_FILE_TYPE);
        client.setBufferSize(DEFAULT_BUFFER_SIZE);
    } else {
        throw new IOException("Login failed on server - " + host + ", port - " + port);
    }

    return client;
}

From source file:org.apache.hadoop.fs.ftp.FtpFs.java

@Override
public int getUriDefaultPort() {
    return FTP.DEFAULT_PORT;
}

From source file:org.apache.hadoop.fs.ftp.TestFTPFileSystem.java

@Test
public void testFTPDefaultPort() throws Exception {
    FTPFileSystem ftp = new FTPFileSystem();
    Assert.assertEquals(FTP.DEFAULT_PORT, ftp.getDefaultPort());
}

From source file:org.paxle.crawler.ftp.impl.FtpStreamHandlerService.java

@Override
public int getDefaultPort() {
    return FTP.DEFAULT_PORT;
}

From source file:org.paxle.crawler.ftp.impl.FtpUrlConnection.java

@Override
public void connect() throws IOException {
    if (this.connected)
        return;/*from   ww  w  .  j  a v a  2 s . c  o  m*/

    /* =======================================================================
     * Connect to host
     * ======================================================================= */
    this.client.connect(this.url.getHost(), (this.url.getPort() != -1) ? this.url.getPort() : FTP.DEFAULT_PORT);
    this.reply = this.client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(this.reply)) {
        client.disconnect();
        String msg = String.format("FTP server '%s' refused connection. ReplyCode: %s", url.getHost(),
                client.getReplyString());
        this.logger.warn(msg);
        throw new FtpConnectionException(msg);
    } else {
        this.logger.debug(
                String.format("Connected to '%s'. ReplyCode: %s", url.getHost(), client.getReplyString()));
    }

    /* =======================================================================
     * Login
     * ======================================================================= */
    String userName = "anonymous", pwd = "anonymous";
    String userInfo = url.getUserInfo();
    if (userInfo != null) {
        int idx = userInfo.indexOf(":");
        if (idx != -1) {
            userName = userInfo.substring(0, idx).trim();
            pwd = userInfo.substring(idx + 1).trim();
        }
    }
    client.login(userName, pwd);
    reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        String msg = String.format("FTP server '%s' login failed. ReplyCode: %s", url.getHost(),
                client.getReplyString());
        this.logger.warn(msg);
        throw new FtpConnectionException(msg);
    }

    /* =======================================================================
     * Change directory
     * ======================================================================= */
    String longpath = uri.getPath();

    if (longpath.endsWith("/")) {
        file = "";
        path = longpath;
    } else {
        int pos = longpath.lastIndexOf("/");
        if (pos == -1) {
            file = longpath;
            path = "/";
        } else {
            path = longpath.substring(0, pos + 1);
            file = longpath.substring(pos + 1);
        }
    }

    client.changeWorkingDirectory(path);
    reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
        client.disconnect();
        String msg = String.format("FTP server '%s' change directory failed. ReplyCode: %s", url.getHost(),
                client.getReplyString());
        this.logger.warn(msg);
        throw new FtpConnectionException(msg);
    }

    // test if the specified file is also an directory
    if (file.length() > 0) {
        client.changeWorkingDirectory(file);
        reply = client.getReplyCode();
        if (FTPReply.isPositiveCompletion(reply)) {
            longpath += "/";
            path = longpath;
            file = "";
        }
    }

    this.isDirectory = (file.length() == 0);
    this.connected = true;
}