色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

利用apache ftpserver搭建ftp服務(wù)器的方法步驟

瀏覽:15日期:2023-03-07 14:40:31
目錄
  • 操作環(huán)境:
  • 一、usermanager采用文件形式管理xml示例如下
  • 二、usermanager采用mysql數(shù)據(jù)庫(kù)管理用戶時(shí),ftpd-mysql.xml示例如下
  • 三、usermanager采用Sqlite數(shù)據(jù)庫(kù)管理用戶時(shí),ftpd-sqlite.xml示例如下
  • 四、解決ftpd.exe在64位windows系統(tǒng)啟動(dòng)失敗的問題
  • 五、python操作sqlite的ftp.db管理(增加刪除)用戶

操作環(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ù)庫(kù)管理用戶時(shí),ftpd-mysql.xml示例如下

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

<?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><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ù)庫(kù)管理用戶時(shí),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><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包還保留著,多了個(gè)操作sqlitejdbc的jar包,下載地址:GitHub - xerial/sqlite-jdbc: SQLite JDBC Driver

四、解決ftpd.exe在64位windows系統(tǒng)啟動(dòng)失敗的問題

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

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

這樣安裝為服務(wù)的時(shí)候就可以正常啟動(dòng)了

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

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

from sqlalchemy import create_enginefrom sqlalchemy import MetaData,Table,Column,Boolean,Integer,Stringimport osengine=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只讀權(quán)限只能同時(shí)登錄一個(gè),admin權(quán)限可讀寫,不限制。

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

標(biāo)簽: Linux Apache
相關(guān)文章:
主站蜘蛛池模板: 国产精品手机在线观看 | 欧美日韩一区二区三区在线 | 伊人短视频 | 亚洲伦乱 | 免费一级a毛片免费观看欧美大片 | 国产精品免费aⅴ片在线观看 | 孩交啪啪网址 | 日本高清va不卡视频在线观看 | 国产a久久精品一区二区三区 | 欧美精品网站 | 精品无人区一区二区三区a 精品午夜国产在线观看不卡 | 日日摸日日碰夜夜爽久久 | 亚洲理论欧美理论在线观看 | 亚洲精品中文字幕在线 | 欧美亚洲国产成人不卡 | 日韩成人精品日本亚洲 | 亚洲欧美韩日 | 久久视奸 | 国产亚洲精品一区二区在线播放 | 欧美成人tv在线观看免费 | 国产视频亚洲 | 美国大毛片| 欧美视频一区二区在线观看 | 特大一级aaaaa毛片 | 久久精品国产99久久 | 日本视频一区二区三区 | 成年人视频在线免费播放 | 日本αv | 久青草国产手机在线观 | 欧美亚洲影院 | 成人网在线免费观看 | 波多野结衣在线播放视频 | 亚洲另类激情综合偷自拍 | 俄罗斯一级成人毛片 | 日韩精品在线一区二区 | 国产一极毛片 | 国产成人精品男人的天堂网站 | 真实国产普通话对白乱子子伦视频 | 黄色免费看片网站 | 日本www视频 | 国产一级在线观看www色 |