开发者

testing whether embedded Mina FTPServer really started

i wrote programmatically a startup code of the apache Server like this:

public void _start()
{
    String Path = "C:\\Dokumente und Einstellungen\\andjock\\Desktop\\ab";

    File ftpDirectory = new File(Path);
    ftpDirectory.mkdirs(); 


    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(2221); 

    try {
        serverFactory.addListener("default", factory.createListener());

        PropertiesUserManagerFactory userFactory = new PropertiesUserManagerFactory();
        File userFile = new File("C:\\Dokumente und Einstellungen\\andjock\\Desktop\\ftpusers.properties");
        userFactory.setFile(userFile);


        UserManager um = userFactory.createUserManager();


        BaseUser user = new BaseUser();
        user.setName("myNewUser");
        user.setPassword("secret");
        user.setHomeDirectory(Path);


        um.save(user);

        serverFactory.setUserManager(um);

        FtpServer ftpServer = serverFactory.createServer();
        ftpServer.start();


    } catch (Exception e) {

        Logger  LOGGER = Logger.getLogger(TestapacheFtpServer.class);
        LOGGER.log(Level.FATAL, "Unable to start test ftpserver", e);
    }

How do i know tha开发者_开发技巧t the server is really working ?

how can i access this apache Server , from the "outside"?

i tried with a telnet and ftp (ftp 127.0.0.1) on my machine but i received:

FTP: connect : unknown error code

does someone got any idea ? i just don't want to rely on the jvm log, but rather test it , and accesing the started it


i figure it out!! i wrote a client using the FTP client library (the apache commons library) to test connectivity and list the files ; something like that

FTPClient ftp = new FTPClient();


    ftp.connect(InetAddress.getLocalHost(), 2221);// or "localhost" in your case
      String loging_success = ftp.login("myNewUser", "secret") == true ? "success" : "failed"; 
      System.out.println("login: "+ loging_success);


      FTPFile[] files = ftp.listFiles();  
      System.out.println("Listed "+files.length+" files.");
      for(FTPFile file : files) {
       System.out.println(file.getName());
      }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜