1.创建数据库及表
使用apache-ftpserver-1.0.6
esftp-db.sql建表,内容如下:
CREATE TABLE FTP_USER (
userid VARCHAR(64) NOT NULL PRIMARY KEY,
userpassword VARCHAR(64),
homedirectory VARCHAR(128) NOT NULL,
enableflag BOOLEAN DEFAULT TRUE,
writepermission BOOLEAN DEFAULT FALSE,
idletime INT DEFAULT 0,
uploadrate INT DEFAULT 0,
downloadrate INT DEFAULT 0,
maxloginnumber INT DEFAULT 0,
maxloginperip INT DEFAULT 0
);
新建用户:insert into FTP_USER values("wch","123456","./res/home",1,0,0,0,0,0,0);
2.修改ftpd-typical.xml
修改 apache-ftpserver-1.0.6
esconfftpd-typical.xml,注意xml命名空间部分:
<?xml version="1.0" encoding="UTF-8"?>
<serverxmlns="http://mina.apache.org/ftpserver/spring/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://mina.apache.org/ftpserver/spring/v1
http://mina.apache.org/ftpserver/ftpserver-1.0.xsd"
id="myServer">
<listeners>
<!-- 设置默认端口是2121,可以修改为自己的端口 -->
<nio-listenername="default"port="2121">
<ssl>
<keystorefile="./res/ftpserver.jks"password="password"/>
</ssl>
</nio-listener>
</listeners>
<!-- 设置用户配置文件以及,密码是否加密 -->
<!-- <file-user-manager file="./res/conf/users.properties" encrypt-passwords="clear"/> -->
<!-- 设置数据库管理用户 -->
<db-user-managerencrypt-passwords="clear">
<!-- 数据源信息,ftpserver为MySQL数据库名称,root/wch,为用户名以及密码 -->
<data-source>
<beans:beanclass="org.apache.commons.dbcp.BasicDataSource">
<beans:propertyname="driverClassName"value="com.mysql.jdbc.Driver"/>
<beans:propertyname="url"value="jdbc:mysql://127.0.0.1/webframe"/>
<beans:propertyname="username"value="root"/>
<beans:propertyname="password"value="wch"/>
</beans:bean>
</data-source>
<insert-user>
INSERT INTO FTP_USER( userid, userpassword, homedirectory, enableflag, writepermission, idletime, uploadrate, downloadrate )
VALUES ( '{userid}', '{userpassword}', '{homedirectory}', {enableflag}, {writepermission}, {idletime}, {uploadrate}, {downloadrate} )
</insert-user>
<update-user>
UPDATE FTP_USER SET userpassword='{userpassword}',
homedirectory='{homedirectory}',
enableflag={enableflag},
writepermission={writepermission},
idletime={idletime},
uploadrate={uploadrate},
downloadrate={downloadrate}
WHERE userid='{userid}'
</update-user>
<delete-user>
DELETE FROM FTP_USER WHERE userid = '{userid}'
</delete-user>
<select-user>
SELECT userid, userpassword, homedirectory, enableflag,
writepermission, idletime, uploadrate, downloadrate,
maxloginnumber, maxloginperip FROM FTP_USER WHERE userid = '{userid}'
</select-user>
<select-all-users>
SELECT userid FROM FTP_USER ORDER BY userid
</select-all-users>
<is-admin>
SELECT userid FROM FTP_USER WHERE userid='{userid}' AND userid='admin'
</is-admin>
<authenticate>
SELECT userpassword from FTP_USER WHERE userid='{userid}'
</authenticate>
</db-user-manager>
</server>
3.增加依赖的jar文件
增加数据库连接需要使用的jar,下载3个jar包到目录apache-ftpserver-1.0.6/common/lib: commons-dbcp-1.x.x.jar、commons-pool-1.x.jar、mysql-connector-java-xxx.jar如下:
4.启动FTPServer
运行命令:ftpd.bat res/conf/ftpd-typical.xml,使用DB方式建议将文件ftpd-typical.xml改名为ftpd-db.xml,如下图:
-------------------------------------------------------------------------------------------------------------------------------