Apache FtpServer扩展【动手实现自己的业务】
public MyFtpServer() throws FtpException{
//读取my-ftpd-full.xml,连接数据库和监控配置,然后来启动server
FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(xmlPath);
FtpServer server = null;
if (ctx.containsBean("server")) {
server = (FtpServer)ctx.getBean("server");
} else {
String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
if (beanNames.length == 1) {
server = (FtpServer)ctx.getBean(beanNames[0]);
} else if (beanNames.length > 1) {
logger.info("Using the first server defined in the configuration, named " + beanNames[0]);
server = (FtpServer)ctx.getBean(beanNames[0]);
} else {
logger.info("XML configuration does not contain a server configuration");
}
}
//ftp服务器启动
server.start();
//在jvm关闭的时候,清理函数
addShutdownHook(server);
}
/**
* 清理的垃圾的钩子函数
* @param engine
*/
private void addShutdownHook(final FtpServer engine)
{
Runnable shutdownHook = new Runnable() {
public void run() {
logger.info("Stopping server...");
engine.stop();
}
};
Runtime runtime = Runtime.getRuntime();
runtime.addShutdownHook(new Thread(shutdownHook));
}



<ftplets>
<ftplet name="MyFtplet">
<beans:bean class="com.shiyi.km.ftpserver.control.MyFtplet">
<!-- <beans:property name="foo" value="123" /> -->
</beans:bean>
</ftplet>
</ftplets>
import java.io.File;
import java.io.IOException; import org.apache.ftpserver.ftplet.DefaultFtpReply;
import org.apache.ftpserver.ftplet.DefaultFtplet;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.FtpRequest;
import org.apache.ftpserver.ftplet.FtpSession;
import org.apache.ftpserver.ftplet.FtpletResult;
import org.apache.ftpserver.ftplet.User;
import org.apache.log4j.Logger; import com.shiyi.km.ftpserver.util.ConfigUtil;
import com.shiyi.km.ftpserver.util.FileUtil; /**
*
* @fileName MyFtplet.java
* @author chenkaideng
* @date 2015年8月11日
* @describe 监控事件
*/
public class MyFtplet extends DefaultFtplet{
private static final Logger logger = Logger.getLogger(MyFtplet.class); @Override
public FtpletResult onUploadStart(FtpSession session, FtpRequest request)
throws FtpException, IOException {
//获取用户信息
User user = session.getUser();
logger.info(String.format("用户信息,用户名【%s】,用户工作目录【%s】", user.getName(),user.getHomeDirectory()));
File file=new File(user.getHomeDirectory()); //判断传入对象是否为一个文件夹对象
if(!file.isDirectory()){
logger.info("用户的HomeDirectory不是一个文件夹,请检查路径是否有误!!");
}
else{
ConfigUtil configUtil = ConfigUtil.getInstance();
if(FileUtil.overSizeLimit(configUtil.getQuota(), file)){
logger.error(String.format("目前用户[%s]目录下的文件总大小超过配额!!!", user.getName()));
session.write(new DefaultFtpReply(228, "The files under the directory over quota"));
return FtpletResult.DISCONNECT;
}
}
return super.onUploadStart(session, request);
}
}
Apache FtpServer扩展【动手实现自己的业务】的更多相关文章
- springboot整合apache ftpserver详细教程(看这一篇就够了)
原创不易,如需转载,请注明出处https://www.cnblogs.com/baixianlong/p/12192425.html,否则将追究法律责任!!! 一.Apache ftpserver相关 ...
- 使用Apache FtpServer搭建FTP服务器 [FlashFXP]
<server xmlns="http://mina.apache.org/ftpserver/spring/v1" xmlns:xsi="http://www.w ...
- 01.Apache FtpServer配置
1.解压Apache FTPServer 将下载下来的压缩包(ftpserver-1.0.6.zip)解压到本地,其目录结构如下图: 2.修改users.properties 修改 \apache-f ...
- apache FtpServer 整合spring部署
我们在项目中可能会出现这样的需求,使用ftp上传很大的文件后对需要对文件进行相应的逻辑处理,这时我们可以使用apache ftpServer来处理这段逻辑,只要我们做相应的部署和编写我们的逻辑代码,这 ...
- apache FtpServer整合spring逻辑处理
上面我们的部署工作完成了,那么文件上传下载后,ftpserver会自动相应我们的上传下载操作,也就是说ftpServer服务器会得到触发,那么我们如果要得到文件的一些信息,比如说文件的路径.大小.类型 ...
- Apache FtpServer 实现文件的上传和下载
1 下载需要的jar包 Ftp服务器实现文件的上传和下载,主要依赖jar包为: 2 搭建ftp服务器 参考Windows 上搭建Apache FtpServer,搭建ftp服务器 3 主要代码 在ec ...
- (转载)Windows 上搭建Apache FtpServer
因工作需要,最近经常接触到FTP,今天我来介绍一个开源的FTP服务器,那就是Apache FTPServer,Apache FTPServer是一个100%纯Java的FTP服务器. 它的设计是基于现 ...
- Apache和Tomcat整合(一个Apache 不同域名处理多个不同业务)
一.简介 在项目中,几乎任何一个项目都包括静态资源和动态请求两大部分.特别对于门户网站这样的项目,静态内容资源会更多,我们使用一般的 Tomcat 部署时,Tomcat 对静态资源的处理能力比较慢,至 ...
- android学习:Android上面部署Apache FTPServer
经过了几天的研究,终于Apache FTPServer在Android的配置和使用上有了一些心得,现在分享出来,提供给大家参考,说到这儿又不得不吐槽一下这要命的转载了,找Apache FTPServe ...
随机推荐
- Redis系统管理相关指令简介
常用命令列表 DBSIZE 返回当前数据库 Key 的数量 INFO ...
- Learning Puppet — Resource Ordering
Learning Puppet — Resource Ordering Learn about dependencies and refresh events, manage the relation ...
- 重复ID的记录,只显示其中1条
--重复ID的记录,只显示其中1条 --生成原始表 select * into #tempTable from ( select '1' as id ,'a' as name union all se ...
- Thinkpad X240修改bios引导方式
来源:http://blog.csdn.net/jsship/article/details/19121149 修改笔记本的BIOS设置!这是非常重要的步骤之一.否则,你的U盘不能引导手提电脑进入PE ...
- 【mybatis】之批量添加
mybatis批量添加xml <insert id="batchCreate"> INSERT INTO `roomer` (`order`,name,idCard,m ...
- ASP.net中网站访问量统计方法代码(在线人数,本月访问,本日访问,访问流量,累计访问)
一.建立一个数据表IPStat用于存放用户信息 我在IPStat表中存放的用户信息只包括登录用户的IP(IP_Address),IP来源(IP_Src)和登录时间 (IP_DateTime),些表的信 ...
- (WF)
Caught: System.InvalidOperationException: The argument of type 'XXX' cannot be used. Make sure that ...
- [jQuery].scrollTop() 函数详解
scrollTop()函数用于设置或返回当前匹配元素相对于垂直滚动条顶部的偏移. 当一个元素的实际高度超过其显示区域的高度时,在一定的设置下,浏览器会为该元素显示相应的垂直滚动条.此时,scrollT ...
- room-views-用窗口颜色清除背景(Clear Background with Window Colour)选项
这个选项是默认开启的,它的作用是在游戏每一帧绘制以前,都用一个颜色打底(覆盖整个游戏场景包括背景,从而实现背景清除),然后在这个基础上再画背景.场景等等. 如果关闭,则在游戏每一帧以前绘制背景(绘制背 ...
- linux下安装mysql数据库与相关操作
如下命令都是用root身份安装,或者在命令前加上sudo 采用yum安装方式安装 yum install mysql #安装mysql客户端 yum install mysql-server #安装m ...