Example #1
0
  /**
   * Starts SSL FTP server
   *
   * @throws Exception
   */
  public static void startSSLServer() throws Exception {

    log.info(
        "Starting Hdfs-Over-Ftp SSL server. ssl-port: "
            + sslPort
            + " ssl-data-ports: "
            + sslPassivePorts
            + " hdfs-uri: "
            + hdfsUri);

    HdfsOverFtpSystem.setHDFS_URI(hdfsUri);

    DataConnectionConfigurationFactory Dccf = new DataConnectionConfigurationFactory();
    Dccf.setPassivePorts(sslPassivePorts);
    DataConnectionConfiguration dataCon = Dccf.createDataConnectionConfiguration();

    MySslConfiguration ssl = new MySslConfiguration();
    ssl.setKeystoreFile(new File("ftp.jks"));
    ssl.setKeystoreType("JKS");
    ssl.setKeyPassword("333333");

    ListenerFactory lf = new ListenerFactory();
    lf.setDataConnectionConfiguration(dataCon);
    lf.setPort(sslPort);
    lf.setImplicitSsl(true);
    lf.setSslConfiguration(ssl);

    FtpServerFactory fsf = new FtpServerFactory();
    fsf.addListener("default", lf.createListener());

    // TODO 搞清楚HdfsUserManager的两个null参数应该改成什么。
    HdfsUserManager userManager = new HdfsUserManager(null, null);
    final File file = loadResource("/users.properties");
    // 	userManager.setFile(new File("users.conf"));
    userManager.setFile(file);

    fsf.setUserManager(userManager);
    fsf.setFileSystem(new HdfsFileSystemManager());

    FtpServer server = fsf.createServer();

    server.start();
  }
  void Config2() {
    //		Now, let's make it possible for a client to use FTPS (FTP over SSL) for the default
    // listener.

    FtpServerFactory serverFactory = new FtpServerFactory();

    ListenerFactory factory = new ListenerFactory();

    // set the port of the listener
    factory.setPort(2221);

    // define SSL configuration
    SslConfigurationFactory ssl = new SslConfigurationFactory();
    ssl.setKeystoreFile(new File(ftpConfigDir + "ftpserver.jks"));
    ssl.setKeystorePassword("password");

    // set the SSL configuration for the listener
    factory.setSslConfiguration(ssl.createSslConfiguration());
    factory.setImplicitSsl(true);

    // replace the default listener
    serverFactory.addListener("default", factory.createListener());

    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    userManagerFactory.setFile(new File(ftpConfigDir + "users.properties"));

    serverFactory.setUserManager(userManagerFactory.createUserManager());

    // start the server
    FtpServer server = serverFactory.createServer();
    this.mFtpServer = server;
    try {
      server.start();
    } catch (FtpException e) {
      e.printStackTrace();
    }
  }