测试嵌入式Mina FTPServer是否真正启动

发布于 2024-11-07 15:09:37 字数 1441 浏览 0 评论 0原文

我以编程方式编写了 apache 服务器的启动代码,如下所示:

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);
    }

我如何知道服务器是否真正工作?

我如何从“外部”访问这个 apache 服务器?

我尝试在我的机器上使用 telnet 和 ftp (ftp 127.0.0.1),但我收到:

FTP:连接:未知错误代码

有人知道吗?我只是不想依赖 jvm 日志,而是测试它,并访问启动它

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 that 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2024-11-14 15:09:37

我明白了!我使用 FTP 客户端库(apache commons 库)编写了一个客户端来测试连接并列出文件;类似的东西

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());
      }

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());
      }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文