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字段對應 的家目錄

 

  成功對比分析:

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM