02.Apache FtpServer使用数据库管理用户

 

1.创建数据库及表

使用\apache-ftpserver-1.0.6\res\ftp-db.sql建表,内容如下:
  1. CREATE TABLE FTP_USER (
  2. userid VARCHAR(64) NOT NULL PRIMARY KEY,
  3. userpassword VARCHAR(64),
  4. homedirectory VARCHAR(128) NOT NULL,
  5. enableflag BOOLEAN DEFAULT TRUE,
  6. writepermission BOOLEAN DEFAULT FALSE,
  7. idletime INT DEFAULT 0,
  8. uploadrate INT DEFAULT 0,
  9. downloadrate INT DEFAULT 0,
  10. maxloginnumber INT DEFAULT 0,
  11. maxloginperip INT DEFAULT 0
  12. );
新建用户: 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\res\conf\ftpd-typical.xml,注意xml命名空间部分:
  1. xml version="1.0" encoding="UTF-8"?>
  2. xmlns="http://mina.apache.org/ftpserver/spring/v1"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:beans="http://www.springframework.org/schema/beans"
  5. xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  8. http://mina.apache.org/ftpserver/spring/v1
  9. http://mina.apache.org/ftpserver/ftpserver-1.0.xsd"
  10. id="myServer">
  11. name="default"port="2121">
  12. file="./res/ftpserver.jks"password="password"/>
  13. encrypt-passwords="clear">
  14. class="org.apache.commons.dbcp.BasicDataSource">
  15. name="driverClassName"value="com.mysql.jdbc.Driver"/>
  16. name="url"value="jdbc:mysql://127.0.0.1/webframe"/>
  17. name="username"value="root"/>
  18. name="password"value="wch"/>
  19. INSERT INTO FTP_USER( userid, userpassword, homedirectory, enableflag, writepermission, idletime, uploadrate, downloadrate )
  20. VALUES ( '{userid}', '{userpassword}', '{homedirectory}', {enableflag}, {writepermission}, {idletime}, {uploadrate}, {downloadrate} )
  21. UPDATE FTP_USER SET userpassword='{userpassword}',
  22. homedirectory='{homedirectory}',
  23. enableflag={enableflag},
  24. writepermission={writepermission},
  25. idletime={idletime},
  26. uploadrate={uploadrate},
  27. downloadrate={downloadrate}
  28. WHERE userid='{userid}'
  29. DELETE FROM FTP_USER WHERE userid = '{userid}'
  30. SELECT userid, userpassword, homedirectory, enableflag,
  31. writepermission, idletime, uploadrate, downloadrate,
  32. maxloginnumber, maxloginperip FROM FTP_USER WHERE userid = '{userid}'
  33. SELECT userid FROM FTP_USER ORDER BY userid
  34. SELECT userid FROM FTP_USER WHERE userid='{userid}' AND userid='admin'
  35. SELECT userpassword from FTP_USER WHERE userid='{userid}'
 

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 如下:
02.Apache FtpServer使用数据库管理用户_第1张图片
 

4.启动FTPServer

运行命令: ftpd . bat   res / conf / ftpd - typical . xml,使用DB方式建议将文件 ftpd - typical . xml 改名为 ftpd-db.xml ,如下图:
02.Apache FtpServer使用数据库管理用户_第2张图片
------------------------------------------------------------------------------------------------------------------------------- 



来自为知笔记(Wiz)



转载于:https://www.cnblogs.com/LiZhiW/p/4794450.html

你可能感兴趣的:(数据库,java)