使用apache的ftpserver搭建ftp服务器

来源:互联网 发布:js点击链接下载文件 编辑:程序博客网 时间:2024/05/16 16:16

不用框架的话,可以用windows自带的ftp工具搭建,不过要下载i386之类的组件。apache提供了一套ftp服务器工具。下载apache-ftpserver-1.0.6.

解压到ftpserver就行了。如果不配置的话,启动bin下的ftpd.bat就行了,浏览器输入ftp://localhost:2121就行了。


打开该文件,可以看到:

rem ----- Create CLASSPATH --------------------------------------------set FTPD_CLASSPATH=%CLASSPATH%;%FTPD_HOME%\common\classes;cd /d "%FTPD_HOME%\common\lib"for %%i in ("*.jar") do call "%FTPD_HOME%\bin\appendcp.bat" "%FTPD_HOME%\common\lib\%%i"cd /d %FTPD_HOME%

这很简单吧,看看就明白了。

如果要安全和可以增加用户,那就要配置数据库了,当然,ftpserver提供了这样的功能。


apache的ftp文件目录和配置都在res下,进入可以看到了。

# Password is "admin"ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3ftpserver.user.admin.homedirectory=./res/homeftpserver.user.admin.enableflag=trueftpserver.user.admin.writepermission=trueftpserver.user.admin.maxloginnumber=0ftpserver.user.admin.maxloginperip=0ftpserver.user.admin.idletime=0ftpserver.user.admin.uploadrate=0ftpserver.user.admin.downloadrate=0ftpserver.user.anonymous.userpassword=ftpserver.user.anonymous.homedirectory=./res/homeftpserver.user.anonymous.enableflag=trueftpserver.user.anonymous.writepermission=falseftpserver.user.anonymous.maxloginnumber=20ftpserver.user.anonymous.maxloginperip=2ftpserver.user.anonymous.idletime=300ftpserver.user.anonymous.uploadrate=4800ftpserver.user.anonymous.downloadrate=4800

匿名用户和admin登录配置。


<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to you under the Apache License, Version2.0 (the "License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0 Unless required byapplicable law or agreed to in writing, software distributed under theLicense is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied. See the License forthe specific language governing permissions and limitations under theLicense.--><server xmlns="http://mina.apache.org/ftpserver/spring/v1"xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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"><!--Use this section to define custom listeners, or to redefine thedefault listener, aptly named "default"--><listeners><nio-listener name="default" port="2222" implicit-ssl="true"idle-timeout="60" local-address="1.2.3.4"><ssl><keystore file="mykeystore.jks" password="secret"key-password="otherSecret" /><truststore file="mytruststore.jks" password="secret" /></ssl><data-connection idle-timeout="60"><active enabled="true" local-address="1.2.3.4" local-port="2323"ip-check="true" /><passive ports="123-125" address="1.2.3.4" external-address="1.2.3.4" /></data-connection><blacklist>1.2.3.0/16, 1.2.4.0/16, 1.2.3.4</blacklist></nio-listener></listeners><!--Use this section to define your Ftplets, they are configured likeregular Spring beans--><ftplets><ftplet name="ftplet1"><beans:bean class="org.apache.ftpserver.examples.MyFtplet"><beans:property name="foo" value="123" /></beans:bean></ftplet></ftplets><!-- The user manager, choose one --><file-user-manager file="users.properties"encrypt-passwords="true" /><!--<db-user-manager><data-source><beans:bean class="some.datasoure.class" /></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> --><!-- The file system --><native-filesystem case-insensitive="false"create-home="true" /><!--Use this section to define custom commands. Custom commands can alsooverride already existing commands--><commands use-default="false"><command name="MYHELP"><beans:bean class="org.apache.ftpserver.examples.MYHELP" /></command></commands><!-- Define the available languages --><messages languages="se, no ,da" /></server>

ftpserver全配置文件。


<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to you under the Apache License, Version2.0 (the "License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0 Unless required byapplicable law or agreed to in writing, software distributed under theLicense is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied. See the License forthe specific language governing permissions and limitations under theLicense.--><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 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" /></server>

一般配置文件。


需要哪些功能,在一般配置文件增加,或者在全配置文件内放开,修改后,要进入bin目录,执行ftpd.bat res/conf/ftpd-.xx.xml才生效。


需要新增用户,就放开数据库的配置。执行:

CREATE TABLE FTP_USER (         userid VARCHAR(64) NOT NULL PRIMARY KEY,          userpassword VARCHAR(64),         homedirectory VARCHAR(128) NOT NULL,                enableflag BOOLEAN DEFAULT TRUE,       writepermission BOOLEAN DEFAULT FALSE,          idletime INT DEFAULT 0,                uploadrate INT DEFAULT 0,                downloadrate INT DEFAULT 0,   maxloginnumber INT DEFAULT 0,   maxloginperip INT DEFAULT 0);

增加一个用户,增加一个ftp目录等等。


0 0
原创粉丝点击