| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
12年前发布

Java 嵌入式 FTP server

FTP server的有点可靠和高效的传输数据,嵌入式FTP server的用途大家可以想想,我一般用来监控文件上传、下载事件,方便、轻量,贴出关键代码

 /**       * FTP Server 启动       */      public void start() {          FtpServerFactory serverFactory = new FtpServerFactory();            ListenerFactory factory = new ListenerFactory();            // set the port of the listener          factory.setPort(21);          if (LOG.isInfoEnabled()) {              LOG.info("----------------Ftp server 端口21----------------------------");          }          // replace the default listener          serverFactory.addListener("default", factory.createListener());            //设置用户配置信息          PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();          userManagerFactory.setFile(SysConfig.getInstance().getConfigFile());              if (LOG.isInfoEnabled()) {              LOG.info("----------------Ftp server 设置用户配置信息----------------------------");          }          //注册FTP事件监听          Map<String, Ftplet> ftplets = new LinkedHashMap<String, Ftplet>();          ftplets.put(FtpletNotification.class.getName(), new FtpletNotification());          serverFactory.setFtplets(ftplets);          if (LOG.isInfoEnabled()) {              LOG.info("----------------Ftp server 注册FTP事件监听----------------------------");          }          serverFactory.setUserManager(userManagerFactory.createUserManager());          if (LOG.isInfoEnabled()) {              LOG.info("----------------Ftp server 准备启动----------------------------");          }          // start the server          server = serverFactory.createServer();          try {              server.start();              port = serverFactory.getListener("default").getPort();              serverAddress = serverFactory.getListener("default").getServerAddress();              if(serverAddress == null) {                  try {                      serverAddress= InetAddress.getLocalHost().getHostAddress();                  } catch (UnknownHostException e) {                      e.printStackTrace();                  }              }              if (LOG.isInfoEnabled()) {                  LOG.info("----------------Ftp serverAddress----------------------------" + serverAddress);              }              if (LOG.isInfoEnabled()) {                  LOG.info("----------------Ftp server 启动成功----------------------------");              }          } catch (FtpException e) {              e.printStackTrace();              if (LOG.isErrorEnabled()) {                  LOG.error("FTP server 启动失败 ", e);              }          }      }

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1338508795948.html
FTP FTP服务器