亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

利用apache?ftpserver搭建ftp服務器的方法步驟

 更新時間:2022年05月20日 08:35:26   作者:逆水寒龍  
本文主要介紹了利用apache?ftpserver搭建ftp服務器的方法步驟,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

操作環(huán)境:

  • 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數(shù)據(jù)庫管理用戶時,ftpd-mysql.xml示例如下

目前數(shù)據(jù)庫管理用戶時采用的明文存儲,salted和md5的方式?jīng)]有測試成功,如有測試成功的朋友請指導一下。

<?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版本有區(qū)別

三、usermanager采用Sqlite數(shù)據(jù)庫管理用戶時,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系統(tǒng)啟動失敗的問題

需下載tomcat包,目前測試的這個版本可行tomcat-7 v7.0.109 (apache.org)

放入apache ftpserver bin目錄里替換原有的ftpd.exe

這樣安裝為服務的時候就可以正常啟動了

五、python操作sqlite的ftp.db管理(增加刪除)用戶

自己搞了個python腳本,采用了sqlalchemy來操作數(shù)據(jù)庫

from sqlalchemy import create_engine
from sqlalchemy import MetaData,Table,Column,Boolean,Integer,String
import os

engine=create_engine('sqlite:///ftp.db')
conn=engine.connect()

metadata=MetaData()

ftpusers=Table('FTP_USER',metadata,
    Column('userid',String(64),primary_key=True),
    Column('userpassword',String(64),nullable=False),
    Column('homedirectory',String(128),nullable=False),
    Column('enableflag',Boolean(),default=True),
    Column('writepermission',Boolean(),default=True),
    Column('idletime',Integer(),default=0),
    Column('uploadrate',Integer(),default=0),
    Column('downloadrate',Integer(),default=0),
    Column('maxloginnumber',Integer(),default=0),
    Column('maxloginperip',Integer(),default=0)
)

metadata.create_all(engine)

def addgeneraluser():

	deluser = ftpusers.delete().where(ftpusers.c.userid=="nic")
	rs = conn.execute(deluser)

	dirname="./files/alluser"
	if not os.path.exists(dirname):
		os.mkdir(dirname)

	ins=ftpusers.insert().values(
		userid="nic",
		userpassword="123321",
		homedirectory=dirname,
		writepermission=0,
		maxloginnumber=1
	)

	result=conn.execute(ins)

def addadmin():
	deladmin = ftpusers.delete().where(ftpusers.c.userid=="admin")
	rs = conn.execute(deladmin)

	ins=ftpusers.insert().values(
		userid="admin",
		userpassword="123456",
		homedirectory="./files",
		writepermission=1
	)

	result=conn.execute(ins)

def getusers():
	sel=ftpusers.select()
	rs=conn.execute(sel)
	print(rs.fetchall())
	
addgeneraluser()
getusers()

可以方便的增加用戶了,generaluser只讀權限只能同時登錄一個,admin權限可讀寫,不限制。

到此這篇關于利用apache ftpserver搭建ftp服務器的方法步驟的文章就介紹到這了,更多相關apache ftpserver搭建ftp內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Apache中301重定向的配置代碼

    Apache中301重定向的配置代碼

    Apache下301重定向代碼(因為我使用的是WINDOWS 2003 + APACHE 所以本文僅限APACHE服務器使用。)
    2011-02-02
  • linux中嘆號命令(!)的使用小結

    linux中嘆號命令(!)的使用小結

    這篇文章主要給大家介紹了關于linux中嘆號命令(!)的使用的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-11-11
  • 一條命令讓你明白shell中read命令的常用參數(shù)

    一條命令讓你明白shell中read命令的常用參數(shù)

    今天小編就為大家分享一篇關于一條命令讓你明白shell中read命令的常用參數(shù),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • CentOS服務器+監(jiān)控寶SNMP監(jiān)控全攻略分享

    CentOS服務器+監(jiān)控寶SNMP監(jiān)控全攻略分享

    很多人和Sudu一樣都想使用監(jiān)控寶去監(jiān)控自己的linux服務器,但是因為安裝snmp存在一些問題導致無法成功設置snmp的設置。
    2010-12-12
  • 詳解阿里云Linux啟動tomcat并能外網(wǎng)訪問

    詳解阿里云Linux啟動tomcat并能外網(wǎng)訪問

    本篇文章主要介紹了詳解阿里云Linux啟動tomcat并能外網(wǎng)訪問,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • CentOS 6.5上的Tomcat啟動報錯問題解決方法

    CentOS 6.5上的Tomcat啟動報錯問題解決方法

    最近在搭建虛擬機環(huán)境,裝的是CentOSQL 6.5版本,然后裝的OpenJDK1.7,在Apache下載了一個純凈的Tomcat放到虛擬機上啟動報錯了
    2016-08-08
  • Apache下ModSecurity的安裝啟用與配置

    Apache下ModSecurity的安裝啟用與配置

    這篇文章主要介紹了Apache下ModSecurity的安裝啟用與配置,需要的朋友可以參考下
    2018-10-10
  • 詳解如何在 CentOS 7 上安裝和安全配置 MariaDB 10

    詳解如何在 CentOS 7 上安裝和安全配置 MariaDB 10

    這篇文章主要介紹了詳解如何在 CentOS 7 上安裝和安全配置 MariaDB 10,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • 詳解linux中nano命令

    詳解linux中nano命令

    這篇文章主要介紹了詳解linux中nano命令,詳細的介紹了nano命令的用法,非常具有實用價值,需要的朋友可以參考下
    2017-09-09
  • Apache中配置支持CORS(跨域資源共享)實例

    Apache中配置支持CORS(跨域資源共享)實例

    這篇文章主要介紹了Apache中配置支持CORS(跨域資源共享)實例,本文給出了一個完整的apache、PHP、JavaScript結合實現(xiàn)的跨域資源共享實例,需要的朋友可以參考下
    2015-01-01

最新評論