本文整理自网络,侵删。
目录
- 操作环境:
- 一、usermanager采用文件形式管理xml示例如下
- 二、usermanager采用mysql数据库管理用户时,ftpd-mysql.xml示例如下
- 三、usermanager采用Sqlite数据库管理用户时,ftpd-sqlite.xml示例如下
- 四、解决ftpd.exe在64位windows系统启动失败的问题
- 五、python操作sqlite的ftp.db管理(增加删除)用户
操作环境:
- win2012r2 x64 datacenter
- Apache FtpServer 1.2.0
- Java SE Development Kit 8u333
- commons-dbcp2-2.9.0.jar
- commons-pool2-2.11.1.jar
- mysql server 8.0.29
- mysql-connector-java-8.0.29.jar
- sqlite
- sqlite-jdbc-3.36.0.3.jar
如下图:
一、usermanager采用文件形式管理xml示例如下
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <server xmlns="http://mina.apache.org/ftpserver/spring/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://mina.apache.org/ftpserver/spring/v1 https://mina.apache.org/ftpserver-project/ftpserver-1.0.xsd " id="myServer"> <listeners> <nio-listener name="default" port="21"> <ssl> <keystore file="./res/ftpserver.jks" password="password" /> </ssl> </nio-listener> </listeners> <file-user-manager file="./res/conf/users.properties" /> </server>
二、usermanager采用mysql数据库管理用户时,ftpd-mysql.xml示例如下
目前数据库管理用户时采用的明文存储,salted和md5的方式没有测试成功,如有测试成功的朋友请指导一下。
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <server xmlns="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> <nio-listener name="default" port="21"> <ssl> <keystore file="./res/ftpserver.jks" password="password" /> </ssl> </nio-listener> </listeners> <db-user-manager encrypt-passwords="clear"> <data-source> <beans:bean class="org.apache.commons.dbcp2.BasicDataSource"> <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" /> <beans:property name="url" value="jdbc:mysql://localhost/ftpserver" /> <beans:property name="username" value="root" /> <beans:property name="password" value="123456" /> </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>
注意:org.apache.commons.dbcp2.BasicDataSource,看最新的commons.dbcp命名空间和1.x版本有区别
三、usermanager采用Sqlite数据库管理用户时,ftpd-sqlite.xml示例如下
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <server xmlns="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> <nio-listener name="default" port="21"> <ssl> <keystore file="./res/ftpserver.jks" password="password" /> </ssl> </nio-listener> </listeners> <db-user-manager encrypt-passwords="clear"> <data-source> <beans:bean class="org.apache.commons.dbcp2.BasicDataSource"> <beans:property name="driverClassName" value="org.sqlite.JDBC" /> <beans:property name="url" value="jdbc:sqlite:ftp.db" /> </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>
注意:commons的jar包还保留着,多了个操作sqlitejdbc的jar包,下载地址:GitHub - xerial/sqlite-jdbc: SQLite JDBC Driver
四、解决ftpd.exe在64位windows系统启动失败的问题
需下载tomcat包,目前测试的这个版本可行tomcat-7 v7.0.109 (apache.org)
相关阅读 >>
Sqlite数据库的介绍与java操作Sqlite的实例讲解
c#中实现在32位、64位系统下自动切换不同的Sqlite dll文件
Sqlitestudio打开后如何切换成简体中文Sqlitestudio绿色版中文设置方法介绍
更多相关阅读请进入《Sqlite》频道 >>
数据库系统概念 第6版
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » 利用apacheftpserver搭建ftp服务器的方法步骤
标签:Sqlite
相关推荐
评论
管理员已关闭评论功能...