您的位置:首页 > 教程 > linux > 利用apache ftpserver搭建ftp服务器的方法步骤

利用apache ftpserver搭建ftp服务器的方法步骤

2022-06-20 14:50:22 来源:易采站长站 作者:

利用apache ftpserver搭建ftp服务器的方法步骤

目录操作环境:一、usermanager采用文件形式管理xml示例如下二、usermanager采用mysql数据库管理用户时,ftpd-mysql.xml示例如下三、usermanager采用Sql...ViI站长之家-易采站长站-Easck.Com

目录
操作环境:
一、usermanager采用文件形式管理xml示例如下
二、usermanager采用mysql数据库管理用户时,ftpd-mysql.xml示例如下
三、usermanager采用Sqlite数据库管理用户时,ftpd-sqlite.xml示例如下
四、解决ftpd.exe在64位windows系统启动失败的问题
五、python操作sqlite的ftp.db管理(增加删除)用户

ViI站长之家-易采站长站-Easck.Com

操作环境:

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

如下图:ViI站长之家-易采站长站-Easck.Com

利用apacheftpserver搭建ftp服务器的方法步骤ViI站长之家-易采站长站-Easck.Com

ViI站长之家-易采站长站-Easck.Com

一、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>

ViI站长之家-易采站长站-Easck.Com

二、usermanager采用mysql数据库管理用户时,ftpd-mysql.xml示例如下

目前数据库管理用户时采用的明文存储,salted和md5的方式没有测试成功,如有测试成功的朋友请指导一下。ViI站长之家-易采站长站-Easck.Com

<?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版本有区别ViI站长之家-易采站长站-Easck.Com

ViI站长之家-易采站长站-Easck.Com

三、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 DriverViI站长之家-易采站长站-Easck.Com

ViI站长之家-易采站长站-Easck.Com

四、解决ftpd.exe在64位windows系统启动失败的问题

需下载tomcat包,目前测试的这个版本可行tomcat-7 v7.0.109 (apache.org)ViI站长之家-易采站长站-Easck.Com

利用apacheftpserver搭建ftp服务器的方法步骤ViI站长之家-易采站长站-Easck.Com

放入apache ftpserver bin目录里替换原有的ftpd.exeViI站长之家-易采站长站-Easck.Com

这样安装为服务的时候就可以正常启动了ViI站长之家-易采站长站-Easck.Com

ViI站长之家-易采站长站-Easck.Com

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

自己搞了个python脚本,采用了sqlalchemy来操作数据库ViI站长之家-易采站长站-Easck.Com

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权限可读写,不限制。ViI站长之家-易采站长站-Easck.Com

到此这篇关于利用apache ftpserver搭建ftp服务器的方法步骤的文章就介绍到这了,更多相关apache ftpserver搭建ftp内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!ViI站长之家-易采站长站-Easck.Com

ViI站长之家-易采站长站-Easck.Com

如有侵权,请联系QQ:279390809 电话:15144810328

相关文章

  • Linux下用GHOST来做系统备份

    Linux下用GHOST来做系统备份

    在Windows系统下备份我们可以用GHOST工具软件完成,Linux系统不能完全依赖于GHOST工具,一则是GHOST本身是有版权的软件,二是GHOST只支持ext2、ext3文件系统的Linux分区,不支持reiserfs、xfs等
    2019-10-25
  • 给 FreeBSD 12.1 安装 GNOME3 图形界面

    给 FreeBSD 12.1 安装 GNOME3 图形界面

    FreeBSD是一个完全开放的、安全的系统,可以Do it yourself的系统。但是个人还是不喜欢呆板的命令行界面,所有就给 FreeBSD 12.1 安装 GNOME3 图形界面。 开始操作,启动FreeBSD 12.1,以root身份
    2019-10-27
  • Ubuntu Studio一个不错的操作系统

    Ubuntu Studio一个不错的操作系统

    Ubuntu Studio 是一个基于 Ubuntu 而面向音频、视频及图形爱好者的操作系统。本次推出的 Ubuntu Studio 为 7.04 版,目前仅支持 Intel i386 兼容的处理器。 Ubuntu Studio 从大量的开源多媒体创作程序
    2019-10-25
  • 最受欢迎的10款Linux免费游戏

    最受欢迎的10款Linux免费游戏

    图为在Linux下运行的免费游戏America's Army 如果你认为 Linux下没有什么好游戏的话,那就错了!我们来看看Linux下最受欢迎的10款游戏吧,而且这些游戏都是完全免费的! # skyreal update(06-12
    2019-10-25
  • compiz fusion特效使用心得(附3D桌面图)

    compiz fusion特效使用心得(附3D桌面图)

    3D桌面图 LINUX发行版就是好,当大多数人还在沉迷于那些什么风格图标鸟玻璃效果甚至孜孜不倦津津乐道的时候,Linux的高手们已经悄悄为我们开启了一个桌面系统3D的时代。 当我第一次
    2019-10-25
  • Ubuntu 下aMule 的安装配置

    Ubuntu 下aMule 的安装配置

    aMule 是一个类似于 eMule 的多平台 P2P 客户端程序。以下将简略叙述 aMule 在 Ubuntu 中的安装及配置 [High ID] 与 [KAD] 的过程。 安装: sudo apt-get install amule sudo apt-get install amule-utils 如果需要
    2019-10-25
  • JMeter jp@gc - stepping thread group插件

    JMeter jp@gc - stepping thread group插件

    这是一个出单接口压力测试的小例子,了解一下压力测试最最基础的基础。出单接口是用来保险出单的,不需要在UI界面下一步下一步的出单,接口一调数据入库完事~~~。再啰嗦一句接
    2019-10-27
  • Ubuntu 下使用K3B软件刻录光盘(图)

    Ubuntu 下使用K3B软件刻录光盘(图)

    不知大家会不会在Ubuntu下刻录光盘呢?k3b是KDE环境下的一个CD/DVD刻录软件,有非常容易使用的界面,功能比较齐全。用起来感觉就象是win下的Nero一样简单自然,比ubuntu里原来的刻录CD方式
    2019-10-25