如何用java 程序启动Apache-ftpserver 功能

 我来答
千锋教育
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);
}
}

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式