zoukankan      html  css  js  c++  java
  • 02.Apache FtpServer使用数据库管理用户

     

    1.创建数据库及表

    使用apache-ftpserver-1.0.6 esftp-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 esconfftpd-typical.xml,注意xml命名空间部分:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <serverxmlns="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. <listeners>
    12. <!-- 设置默认端口是2121,可以修改为自己的端口 -->
    13. <nio-listenername="default"port="2121">
    14. <ssl>
    15. <keystorefile="./res/ftpserver.jks"password="password"/>
    16. </ssl>
    17. </nio-listener>
    18. </listeners>
    19. <!-- 设置用户配置文件以及,密码是否加密 -->
    20. <!-- <file-user-manager file="./res/conf/users.properties" encrypt-passwords="clear"/> -->
    21. <!-- 设置数据库管理用户 -->
    22. <db-user-managerencrypt-passwords="clear">
    23. <!-- 数据源信息,ftpserver为MySQL数据库名称,root/wch,为用户名以及密码 -->
    24. <data-source>
    25. <beans:beanclass="org.apache.commons.dbcp.BasicDataSource">
    26. <beans:propertyname="driverClassName"value="com.mysql.jdbc.Driver"/>
    27. <beans:propertyname="url"value="jdbc:mysql://127.0.0.1/webframe"/>
    28. <beans:propertyname="username"value="root"/>
    29. <beans:propertyname="password"value="wch"/>
    30. </beans:bean>
    31. </data-source>
    32. <insert-user>
    33. INSERT INTO FTP_USER( userid, userpassword, homedirectory, enableflag, writepermission, idletime, uploadrate, downloadrate )
    34. VALUES ( '{userid}', '{userpassword}', '{homedirectory}', {enableflag}, {writepermission}, {idletime}, {uploadrate}, {downloadrate} )
    35. </insert-user>
    36. <update-user>
    37. UPDATE FTP_USER SET userpassword='{userpassword}',
    38. homedirectory='{homedirectory}',
    39. enableflag={enableflag},
    40. writepermission={writepermission},
    41. idletime={idletime},
    42. uploadrate={uploadrate},
    43. downloadrate={downloadrate}
    44. WHERE userid='{userid}'
    45. </update-user>
    46. <delete-user>
    47. DELETE FROM FTP_USER WHERE userid = '{userid}'
    48. </delete-user>
    49. <select-user>
    50. SELECT userid, userpassword, homedirectory, enableflag,
    51. writepermission, idletime, uploadrate, downloadrate,
    52. maxloginnumber, maxloginperip FROM FTP_USER WHERE userid = '{userid}'
    53. </select-user>
    54. <select-all-users>
    55. SELECT userid FROM FTP_USER ORDER BY userid
    56. </select-all-users>
    57. <is-admin>
    58. SELECT userid FROM FTP_USER WHERE userid='{userid}' AND userid='admin'
    59. </is-admin>
    60. <authenticate>
    61. SELECT userpassword from FTP_USER WHERE userid='{userid}'
    62. </authenticate>
    63. </db-user-manager>
    64. </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,如下图:
    ------------------------------------------------------------------------------------------------------------------------------- 





  • 相关阅读:
    换种方式思考问题
    win7 下的open live writer代码插件
    vue-todolist
    vue-新建项目出错情况分析
    vue新建项目
    AJAX(一、基本知识)
    2016年度工作总结
    常看常遇见之一——BS架构VS CS架构
    thinkjs——session
    关于Listener
  • 原文地址:https://www.cnblogs.com/LiZhiW/p/4794450.html
Copyright © 2011-2022 走看看