Beispiel #1
0
  public void startServer() {
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory factory = new ListenerFactory();

    BaseUser user = new BaseUser();
    user.setName("test");
    user.setPassword("123456");
    user.setHomeDirectory("D:/test");

    int port = 2221;

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

    List<Authority> authorities = new ArrayList<Authority>();
    authorities.add(new WritePermission());
    user.setAuthorities(authorities);

    try {
      serverFactory.getUserManager().save(user);
      FtpServer server = serverFactory.createServer();
      server.start();
    } catch (FtpException e) {
      e.printStackTrace();
    }
  }
  /**
   * Emulates an FTP server
   *
   * @param args - provided arguments
   * @throws FtpException - if an error occurs
   */
  public static void main(final String[] args) throws FtpException {
    FtpServerFactory serverFactory = new FtpServerFactory();
    serverFactory.setUserManager(
        new PropertiesUserManager(
            new Md5PasswordEncryptor(), new File("user.properties"), "admin"));
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(2221);
    serverFactory.addListener("default", factory.createListener());
    FtpServer server = serverFactory.createServer();

    // start the server
    server.start();
  }
  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (null != mFtpServer) {
      mFtpServer.stop();
      mFtpServer = null;
    }
  }
Beispiel #4
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 Config1() {
    //		Now, let's configure the port on which the default listener waits for connections.

    FtpServerFactory serverFactory = new FtpServerFactory();

    ListenerFactory factory = new ListenerFactory();

    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();

    String[] str = {"mkdir", ftpConfigDir};
    try {
      Process ps = Runtime.getRuntime().exec(str);
      try {
        ps.waitFor();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    String filename = ftpConfigDir + "users.properties"; // "/sdcard/users.properties";
    File files = new File(filename);

    userManagerFactory.setFile(files);
    serverFactory.setUserManager(userManagerFactory.createUserManager());
    // set the port of the listener
    factory.setPort(2221);

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

    // start the server
    FtpServer server = serverFactory.createServer();
    this.mFtpServer = server;
    try {
      server.start();
    } catch (FtpException e) {
      e.printStackTrace();
    }
  }
Beispiel #6
0
  /**
   * Starts FTP server
   *
   * @throws Exception
   */
  public static void startServer() throws Exception {

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

    HdfsOverFtpSystem.setHDFS_URI(hdfsUri);

    DataConnectionConfigurationFactory dccf = new DataConnectionConfigurationFactory();
    dccf.setPassivePorts(passivePorts);

    ListenerFactory lf = new ListenerFactory();
    lf.setDataConnectionConfiguration(dccf.createDataConnectionConfiguration());
    lf.setPort(port);
    HashMap<String, Listener> lmap = new HashMap<String, Listener>();
    lmap.put("2222", lf.createListener());

    FtpServerFactory fsf = new FtpServerFactory();
    fsf.addListener("2222", lf.createListener());
    // fsf.setListeners(lmap);

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

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

    FtpServer server = fsf.createServer();

    server.start();
  }
  public ComputerCraftFTP(
      int port, String bindAddress, String pasvPorts, String pasvAddress, String maxFilesize)
      throws FtpException {
    FtpServerFactory serverFactory = new FtpServerFactory();

    ListenerFactory factory = new ListenerFactory();

    // set the host and port of the listener
    if (bindAddress != null && !bindAddress.isEmpty()) factory.setServerAddress(bindAddress);

    factory.setPort(port);

    // Data connection config
    DataConnectionConfigurationFactory configurationFactory =
        new DataConnectionConfigurationFactory();
    if (pasvPorts != null && !pasvPorts.isEmpty()) {
      configurationFactory.setPassivePorts(pasvPorts);
      configurationFactory.setPassiveExternalAddress(pasvAddress);
    }
    factory.setDataConnectionConfiguration(
        configurationFactory.createDataConnectionConfiguration());

    // Connection config
    ConnectionConfigFactory connectionConfigFactory = new ConnectionConfigFactory();
    connectionConfigFactory.setAnonymousLoginEnabled(false);
    serverFactory.setConnectionConfig(connectionConfigFactory.createConnectionConfig());

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

    serverFactory.setUserManager(new CCUserManager(maxFilesize));

    // start the server
    FtpServer server = serverFactory.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();
    }
  }
 @AfterSuite
 public void destroyServer() {
   if (ftpServer != null && !ftpServer.isStopped()) {
     ftpServer.stop();
   }
 }
 @BeforeSuite
 public void initServer() throws FtpException {
   ftpServer.start();
 }