
如何用java 程序启动Apache-ftpserver 功能
1个回答
2016-07-03 · 做真实的自己 用良心做教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注

展开全部
public class FtpServerListener implements ServletContextListener {
public static final String FTPSERVER_CONTEXT_NAME = "org.apache.ftpserver";
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("Stopping FtpServer");
FtpServer server = (FtpServer) sce.getServletContext().getAttribute(FTPSERVER_CONTEXT_NAME);
if(server != null) {
server.stop();
sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);
System.out.println("FtpServer stopped");
} else {
System.out.println("No running FtpServer found");
}
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Starting FtpServer");
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
FtpServer server = (FtpServer) ctx.getBean("myFtpServer");
sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);
try {
server.start();
System.out.println("FtpServer started");
} catch (Exception e) {
throw new RuntimeException("Failed to start FtpServer", e);
}
}
}
public static final String FTPSERVER_CONTEXT_NAME = "org.apache.ftpserver";
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("Stopping FtpServer");
FtpServer server = (FtpServer) sce.getServletContext().getAttribute(FTPSERVER_CONTEXT_NAME);
if(server != null) {
server.stop();
sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);
System.out.println("FtpServer stopped");
} else {
System.out.println("No running FtpServer found");
}
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("Starting FtpServer");
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
FtpServer server = (FtpServer) ctx.getBean("myFtpServer");
sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);
try {
server.start();
System.out.println("FtpServer started");
} catch (Exception e) {
throw new RuntimeException("Failed to start FtpServer", e);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询