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 ...
随机推荐
- CSS设置DIV背景色渐变显示
本文转载自:http://blog.csdn.net/gingerredjade/article/details/12191741 <style type="text/css" ...
- C#读取系统信息
using System; using System.Management; namespace Soyee.Comm { /// <summary> /// Computer Infor ...
- 81 Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
- System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list
static void Main(string[] args) { StringBuilder sb = new StringBuilder(); string test = "124454 ...
- C/C++代码静态分析插件 SourceInsight_Scan
sourceinsight-scan 是一款集成在 SourceInsight 中的c/c++代码静态分析插件,集成了cppcheck,coverity,pclint等业界优秀的静态分析工具的优点. ...
- [实变函数]5.2 非负简单函数的 Lebesgue 积分
1 设 $$\bex \phi(x)=\sum_{i=1}^j c_i\chi_{E_i}(x),\quad c_i\geq 0, \eex$$ 其中 ...
- 转-WebView loadData与loadDataWithBaseURL用法、区别
近期用到WebView加载一些动态的内容的时候遇到一些问题,例如:在加载动态网页时,页面有很多样式表包含一些特殊字符,导致WebView无法识别产生加载异常,程序直接崩溃:另外一个就是加载的网页中有图 ...
- Java注解处理器--annotation学习四
Java中的注解(Annotation)是一个很神奇的东西,特别现在有很多Android库都是使用注解的方式来实现的.一直想详细了解一下其中的原理.很有幸阅读到一篇详细解释编写注解处理器的文章.本文的 ...
- Bug 是改不完滴
- Excel常用函数大全
1.ABS函数 函数名称:ABS 主要功能:求出相应数字的绝对值. 使用格式:ABS(number) 参数说明:number代表需要求绝对值的数值或引用的单元格. 应用举例:如果在B2单元格 ...