本文介绍通过spring 集成的方式来实现。创建spring-apacheFtpServer.xml文件如下图所示
<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
"
id="apacheFtpServer">
<listeners>
<nio-listener name="default" port="21">
</nio-listener>
</listeners>
<file-user-manager file="ftpConfig.properties" />
</server>
引入的属性文件ftpConfig.properties如下所示
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Password is "admin"
ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3
ftpserver.user.admin.homedirectory=F:\\temp
ftpserver.user.admin.enableflag=true
ftpserver.user.admin.writepermission=true
ftpserver.user.admin.maxloginnumber=0
ftpserver.user.admin.maxloginperip=0
ftpserver.user.admin.idletime=0
ftpserver.user.admin.uploadrate=0
ftpserver.user.admin.downloadrate=0
ftpserver.user.anonymous.userpassword=
ftpserver.user.anonymous.homedirectory=F:\\temp
ftpserver.user.anonymous.enableflag=true
ftpserver.user.anonymous.writepermission=false
ftpserver.user.anonymous.maxloginnumber=20
ftpserver.user.anonymous.maxloginperip=2
ftpserver.user.anonymous.idletime=300
ftpserver.user.anonymous.uploadrate=4800
ftpserver.user.anonymous.downloadrate=4800
实现如下java代码。
package com.sdjxd.util;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.impl.DefaultFtpServer;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
* 项目启动的时候,就开启ftp服务器
*
* @author zhen
*
*/
public class ApacheFtpServerListener implements ServletContextListener {
private static final Logger logger = Logger
.getLogger(ApacheFtpServerListener.class);
private static final String FTPSERVER_CONTEXT_NAME = "FTPSERVER_CONTEXT_NAME";
public void contextDestroyed(ServletContextEvent sce) {
logger.info("正在停止FTP服务....");
DefaultFtpServer server = (DefaultFtpServer) sce.getServletContext()
.getAttribute(FTPSERVER_CONTEXT_NAME);
if (server != null) {
server.stop();
sce.getServletContext().removeAttribute(FTPSERVER_CONTEXT_NAME);
logger.info("FTP服务已停止!");
} else {
logger.info("停止FTP服务出错!");
}
}
public void contextInitialized(ServletContextEvent sce) {
logger.info("正在开启FTP服务....");
ApplicationContext ac = WebApplicationContextUtils
.getWebApplicationContext(sce.getServletContext());
DefaultFtpServer server = (DefaultFtpServer) ac
.getBean("apacheFtpServer");
sce.getServletContext().setAttribute(FTPSERVER_CONTEXT_NAME, server);
try {
server.start();
logger.info("FTP服务已开启!");
} catch (FtpException e) {
logger.error(e.getMessage());
}
}
}
最后在web.xml文件中加入监听
<listener>
<description>apache ftp server监听器</description>
<listener-class>com.sdjxd.util.ApacheFtpServerListener</listener-class>
</listener>
至此Ftp文件服务器架设成功,让我们用ftp客户端来测试一下我们的Ftp服务器吧。
注意 写道
Ftp客户端连接服务器编码要用utf-8,否则可能会出现路径或文件名乱码的情况!
由于附件大小的限制,源码放到了CSDN,有需要的童鞋请到这里下载
FtpServer源码
分享到:
相关推荐
从零开始介绍Apache FtpServer,并一步一步教你配置Apache FtpServer,更高级的应用,教你用写代码控制Apache FtpServer及集成到自己的应用中 <!--ftp端口 --> <!--绑定的服务器IP地址,多网卡的时候使用...
基于Apache FtpServer 的Ftp服务器实现,使用了srping集成的方式来实现的。
Apache FtpServer是一个100%纯Java的、基于现有开放式协议基础上、完整、小巧的FTP服务器。此外,FtpServer还可以作为Windows服务器、Unix / Linux后台程序或是被嵌入在Java应用程序而独立运行。有了MINA...
该资源提供了与Apache配合使用的FTP服务器安装包,支持FTP服务的构建。
JavaWeb集群环境下的FTP文件服务器配置使用
NULL 博文链接:https://wjy320.iteye.com/blog/2063535
建议安装好了以后,在去下载个8uftp 这个专门连接各种FTP服务器的客户端,最原始的FTP测试方式可能会无法登录到FTPserver的。具体是什么原因导致的,我也不清楚。那位大神路过可以给解释解释,那就太感谢了。
Apache FtpServer是100%纯Java FTP服务器。它被设计为基于当前可用的开放协议的完整且 可移植的FTP服务器引擎解决方案。FtpServer可以作为Windows服务或Unix / Linux守护程序独立运行, 也可以嵌入Java应用程序中...
Apache Ftp Server 是100%纯Java的FTP服务器软件,它采用MINA网络框架开发具有非常好的性能。Apache FtpServer 既可以嵌到Java应用中使用,也可以做为Windows服务或Unix/Linux Daemon单独运行。此外还提供与Spring ...
apache_ftp_server_demo.zip
配置好的apache ftp服务器,使用cmd cd命令切换到bin目录,运行ftpd.bat ./res/conf/ftpd-typical.xml 即可qiyong典型配置的ftp服务器。apache的东西开源,超赞。
apache-ftpserver文件服务器v1.1.1版本,内含Linux和windows的启动命令及访问方式,当然也可以通过ftpserver官网下载。
Apache Ftp Server 是100%纯Java的FTP服务器软件,它采用MINA网络框架开发具有非常好的性能。Apache FtpServer 既可以嵌到Java应用中使用,也可以做为Windows服务或Unix/Linux Daemon单独运行。此外还提供与Spring ...
可以通过数据库表管理apache ftp服务器的登录用户,方便ftp用户的管理,并且可以通过系统的后台可视化页面对ftp用户进行管理。方便快捷
ftp服务器,解压修改配置文件,然后就可以当做ftp服务器使用
基于apache发布的FTPserver实现的基于hadoop-0.20.2的FTP服务器,可以直接使用,但要进行hadoop网址的基本配置,另外只有一个匿名用户,除了几个我设定的系统文件夹不能删除外,基本具有所有权限。当然,您可以在此...
用java编写的FTP服务器、客户端。服务器底层采用apache FTPserver的JAR包。客户端底层采用sun.net包。两者都可以独立使用。在myeclipse10.6里面编写,java版本是1.6。
用Java实现FTP服务器解决方案.doc
httpd - Apache超文本传输协议服务器 httxt2dbm - 生成RewriteMap指令使用的dbm文件 服务器和支持程序 logresolve - 解析Apache日志中的IP地址为主机名 其他程序 rotatelogs - 滚动Apache日志的管道日志程序 suexec...