Apache FtpServer詳解

來源:互聯網
上載者:User

標籤:apache   apache ftpserver   

FTP 是FileTransfer Protocol(檔案傳輸通訊協定)的英文簡稱,而中文簡稱為“文傳協議”。用於Internet上的控制檔案的雙向傳輸。同時,它也是一個應用程式 (Application)。基於不同的作業系統有不同的FTP應用程式,而所有這些應用程式都遵守同一種協議以傳輸檔案。在FTP的使用當中,使用者經常 遇到兩個概念:"下載"(Download)和"上傳"(Upload)。"下載"檔案就是從遠程主機拷貝檔案至自己的電腦上;"上傳"檔案就是將檔案 從自己的電腦中拷貝至遠程主機上。用Internet語言來說,使用者可通過客戶機程式向(從)遠程主機上傳(下載)檔案。

這裡我們介紹Apache旗下Mina項目下的FtpServer:


OK,咱們還是切入正題吧!詳細步驟如下:

方式一:通過負載檔案的方式,建立Apache FtpServer。

1、下載Apache FtpServer,目前,最新為1.0.6,:http://mina.apache.org/ftpserver-project/downloads.html

2、解壓得到apache-ftpserver-1.0.6;

3、進入apache-ftpserver-1.0.6\res\conf,進行相關配置;

      首先修改users.properties這個檔案

          ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3修改為:

          ftpserver.user.admin.userpassword=admin

     然後修改ftpd-typical.xml檔案

          <file-user-managerfile="./res/conf/users.properties">為

          <file-user-managerfile="./res/conf/users.properties" encrypt-passwords ="clear"/>

4、安裝以及啟動FTPServer;

     進入CMD命令/bin這個目錄下執行(win7環境需要以管理員身份啟動CMD),

     service install (注意:安裝只需安裝一次)

     ftpd.bat res/conf/ftpd-typical.xml(如果看到“FtpServer started”這句話,代表FtpServer啟動成功)

    

5、登陸Apache FtpServer

     開啟瀏覽器,輸入:ftp://hostaddress:port,如:ftp://10.0.0.132:2121,登陸FTP檔案伺服器。

    


方式二:使用資料庫進行驗證(這裡資料庫選用mysql),建立Apache Ftpserver伺服器

1、前面兩步是一樣,下載以及解壓。

2、進入apache-ftpserver-1.0.6\res\conf,進行相關配置;

       首先,選定一個資料庫(這裡使用ftpserver),根據檔案apache-ftpserver-1.0.6/res/ftp-db.sql中的命令建立資料庫;

       接下來,在資料庫中增加一條記錄:insert into FTP_USER values("user1","123456","./res/home",1,0,0,0,0,0,0);

       然後,建立設定檔:ftpd-db.xml

       最後,添加ftpd-db.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/root,為使用者名稱以及密碼 --><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="root" /></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 SETuserpassword='{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 FROMFTP_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}'ANDuserid='admin'</is-admin><authenticate>SELECT userpassword from FTP_USER WHEREuserid='{userid}'</authenticate></db-user-manager></server>

3、導jar包

      增加資料庫連接需要使用的jar,下載3個jar包到目錄apache-ftpserver-1.0.6/common/lib: commons-dbcp-1.2.2.jar、commons-pool-1.3.jar、

       mysql-connector-java-3.1.13-bin.jar

4、安裝以及啟動FTPServer;

       進入CMD命令/bin這個目錄下執行(win7環境需要以管理員身份啟動CMD),

       service install

       ftpd.bat res/conf/ftpd-db.xml(注意:跟前面啟動時載入的XML不相同)

5、登陸Apache FtpServer

      開啟瀏覽器,輸入:ftp://hostaddress:port,如:ftp://10.0.0.132:2121,輸入使用者和密碼:user1  123456,登陸FTP檔案伺服器。


配置詳解如下:

開啟FtpServer安裝目錄,其目錄下有:bin、common、res三個目錄。

1、當前至關心res目錄,下面來看看該目錄:

  a、conf目錄,該目錄下主要存放與FtpServer相關的設定檔,稍後會詳細介紹。

  b、home目錄,該目錄下主要用於存放Ftp伺服器上的檔案(FtpServer預設存放在該目錄下),可通過設定檔修改存放目的地,稍後會詳細介紹。

  c、log目錄,從目錄名稱可得知是存放日誌的地方,一般我們不會關心該目錄。

  b、ftp-db.sql、ftpserver.jks檔案,ftp-db.sql檔案表示如果採用資料庫連接方式建立FTP伺服器時的建表語句

2、conf目錄:

   a、先來看看users.properties檔案,該檔案主要使用者對FtpServer的使用者進行配置。下面來看看該檔案各配置項的詳細說明:

  #密碼為1234   tpserver.user.anonymous.userpassword=1234   #主目錄(FtpServer檔案存放目錄)   ftpserver.user.anonymous.homedirectory=./res/home   #目前使用者可用   ftpserver.user.anonymous.enableflag=true   #具有上傳許可權   ftpserver.user.anonymous.writepermission=true   #最大登陸使用者數為20   ftpserver.user.anonymous.maxloginnumber=20   #同IP登陸使用者數為2   ftpserver.user.anonymous.maxloginperip=2   #空閑時間為300秒   ftpserver.user.anonymous.idletime=300   #上傳速率限制為48位元組每秒   ftpserver.user.anonymous.uploadrate=4800   #下載速率限制為48位元組每秒   ftpserver.user.anonymous.downloadrate=4800

   i、使用者名稱及密碼設定:

     設定使用者名稱: ftpserver.user.xxxxxx .userpassword=1234用於設定密碼,表示當前密碼為1234,xxxxxx為使用者名稱,該名字隨意自訂。

   ii、設定該帳號的主目錄(FtpServer檔案存放目錄)

      設定檔案存放主目錄:ftpserver.user.anonymous.homedirectory=./res/home,表示當前主目錄為FtpServer安裝目錄下,res目錄中的home目錄。

b、再來看看ftpd-typical.xml檔案:

   i、在server根項目下添加一下屬性:(增加了下面屬性後,在IE中無法開啟)

     開啟該xml檔案,找到server根項目,預設server根項目只有一個id屬性值為myServer。

     #最大使用者登入數

     max-logins="20"

     #是否允許使用者匿名登入

     anon-enabled="false"

     #以下三個屬性一般不會進行修改

     max-anon-logins="0"

    max-login-failures="3"

    login-failure-delay="30000"

   ii、修改FtpServer連接埠:

     找到nio-listener元素,修改該元素的port屬性為需要修改的連接埠。

3、關於使用資料連線建立Ftpserver需要說明的點。

ftpd-db.xml中server屬性部分的申明部分一定要寫,否則就會找不到beans,

報錯:The prefix "beans" for element"beans:bean" is not bound;

db-user-manager 的屬性部分(encrypt-passwords="clear")一定要寫,這裡的密碼加密方式為clear,否則會登入不成功;

下面的紅色字型分別表示localhost(資料庫所在的ip地址),ftpserver(資料庫名稱),root(串連資料庫的使用者名稱),root(串連資料庫密碼)。







       

       

Apache FtpServer詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.