apache ftp server的简单入门(数据库验证)

apache的简单校验分为两种,一直是前面提到的properties的校验,具体参考:apache ftp server的简单入门(properties验证)

今天来说一种数据库的校验,这种方式在项目中更加常用:

具体步骤如下:

  第一步:下载解压(我在window上演示,linux上就启动命令由bat的命令换成sh命令即可,不会的自己百度,网上有很多资料)

  

 

  第二步:进入%ftp-server%/res中修改一下数据库文件,并在数据库中创建对于的表    ftpd-db.sql

  

  到这儿还没结束:

  我是mysql演示,就在mysql中说: 在mysql中创建一个数据库,暂定为ftpserver   并在库中创建上面那个权限认证表(我认为的),成功如下:

  

  往表中添加允许登录ftp的用户,

  

INSERT INTO `ftpserver`.`ftp_user` (`userid`, `userpassword`, `homedirectory`, `enableflag`, `writepermission`, `idletime`, `uploadrate`, `downloadrate`, `maxloginnumber`, `maxloginperip`) VALUES ('admin', 'admin', 'D:/', '1', '0', '0', '0', '0', '0', '0');
INSERT INTO `ftpserver`.`ftp_user` (`userid`, `userpassword`, `homedirectory`, `enableflag`, `writepermission`, `idletime`, `uploadrate`, `downloadrate`, `maxloginnumber`, `maxloginperip`) VALUES ('huhy', '123456', './res/home', '1', '0', '0', '0', '0', '0', '0');

  第三步,配置数据库文件,ftpd-mysql.xml   -----------这是从ftpd-typical.xml  cp  过来的,,为了不破坏原来的文件结构,即出错,只需要删除我自己创建的一个文件即可

  

  ftpd-mysql.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="2121">
            <ssl>
                <keystore file="./res/ftpserver.jks" password="password" />
            </ssl>
        </nio-listener>
    </listeners>
    <!-- 将文件方式注释掉 -->
    <!-- <file-user-manager file="./res/conf/users.properties" /> -->
    <db-user-manager encrypt-passwords="clear">
        <!-- 数据源信息,ftpserver为MySQL数据库名称,root/123456,为用户名以及密码 -->
        <data-source>
            <beans:bean class="org.apache.commons.dbcp.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>

第四步: 获取指定jar包放到common/lib下

  主要需要   common-jdbc    common-pools      mysql的连接jar包

  

 

  第五步:

    进入bin下,启动ftp服务:

    service  install

    ftpd.bat  res/conf/ftpd-mysql..xml

    

 

   第六步,验证:

    

 

     注意,这里的用户名密码是指的你数据库表中的用户名和密码,验证成功打开的是你数据库表中homedirectory字段对应 的家目录

 

  成功对比分析:

  

 

posted @ 2017-12-22 10:36  陽66  阅读(2174)  评论(0编辑  收藏  举报