Apache FtpServer[linux] 配置使用

参考文章:http://gongsy.iteye.com/blog/1466024

                  http://liuxiang8484.blog.163.com/blog/static/73479097201211413557727/


Apache FtpServer[linux] 配置使用

1下载ftpServer,地址http://mina.apache.org/ftpserver-project/downloads.html

2解压缩:tar-zvxf  ftpserver-1.0.6.tar.gz

3进入配置文件目录:cdapache-ftpserver-1.0.6/res/conf

4配置用户登录信息【两种:配置文件、数据库】

1)使用文件进行用户登录验证

修改文件 users.properties(其中蓝色字体为用户名,红色字体为密码)
ftpserver.user.
admin.userpassword=admin  # encrypt-passwords ="clear" 明文密码
ftpserver.user.
admin.homedirectory=./res/home
ftpserver.user.
admin.enableflag=true
ftpserver.user.
admin.writepermission=true
ftpserver.user.
admin.maxloginnumber=0
ftpserver.user.
admin.maxloginperip=0
ftpserver.user.
admin.idletime=0
ftpserver.user.
admin.uploadrate=0
ftpserver.user.
admin.downloadrate=0

ftpserver.user.anonymous.userpassword=
ftpserver.user.anonymous.homedirectory=./res/home
ftpserver.user.anonymous.enableflag=true
ftpserver.user.anonymous.writepermission=false
ftpserver.user.anonymous.maxloginnumber=20
ftpserver.user.anonymous.maxloginperip=2
ftpserver.user.anonymous.idletime=300
ftpserver.user.anonymous.uploadrate=4800

执行命令:cpftpd-typical.xml ftpd-file.xml

修改配置文件ftpd-file.xml,其中红色字体为修改部分,密码加密方式修改为clear

默认为MD5加密方式

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">
       
               
                   
               
           

               

       

        encrypt-passwords = "clear" />

退回目录apache-ftpserver-1.0.6/,启动ftp服务 sh bin/ftpd.shres/conf/ftpd-file.xml

执行:ftp 127.0.0.12121    输入用户和密码:admin   admin

使用配置文件的方式这就可以了,配置文件详细说明

users.properties文件存放的是用户名及密码权限等配置信息

用户名为anonymous

#密码为空
tpserver.user.anonymous.userpassword=
#主目录
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

能够通过修改users.properties文件来添加和管理用户及权限等信息。

 

Apache Ftp Server 重要的用途其实是作为一种灵活的嵌入式文件传输方案来使用, 单纯作为FTP来说他的性能也是非常好的,800并发上传文件没有任何问题(linux 4cpu 4g mem scsi)

 

 

2)使用数据库进行验证,这里数据库选用mysql

选定一个数据库(这里使用ftpserver),根据文件apache-ftpserver-1.0.6/res/ftp-db.sql中的命令创建数据库

在数据库中增加一条记录:insert intoFTP_USERvalues("user1","123456","./res/home/user1",1,0,0,0,0,0,0);

创建配置文件:

cd apache-ftpserver-1.0.6/res/conf

cp ftpd-typical.xml ftpd-db.xml

修改配置文件ftpd-db.xml


       
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">
       
               
                   
               
           

               

       

        

       encrypt-passwords= "clear">
               
                   
                       
                       localhost
/ftpserver" />
                       root
" />
                       123456
" />
                   
               
               INSERT INTO FTP_USER (userid, userpassword,
                       homedirectory, enableflag, writepermission, idletime, uploadrate,
                       downloadrate) VALUES ('{userid}', '{userpassword}',
                       '{homedirectory}',
                       {enableflag}, {writepermission}, {idletime},
                       {uploadrate},
                       {downloadrate})
               

                       UPDATE FTP_USER SET
                               userpassword='{userpassword}',homedirectory='{homedirectory}',enableflag={enableflag},writepermission={writepermission},idletime={idletime},uploadrate={uploadrate},downloadrate={downloadrate}
                               WHERE userid='{userid}'
               

                       DELETE FROM FTP_USER WHERE userid = '{userid}'
               

                       SELECT userid, userpassword, homedirectory,
                               enableflag, writepermission, idletime, uploadrate, downloadrate,
                               maxloginnumber, maxloginperip FROM
                               FTP_USER WHERE userid = '{userid}'
               

                       SELECT userid FROM FTP_USER ORDER BY userid
               

                       SELECT userid FROM FTP_USER WHERE userid='{userid}'
                               AND
                               userid='admin'
               

                       SELECT userpassword from FTP_USER WHERE
                               userid='{userid}'

       

说明:server属性部分的红色字体一定要写,否则就会找不到beans,报错:The prefix "beans" for element "beans:bean"is not bounddb-user-manager的属性部分的红色字体一定要写,这里的密码加密方式为clear,否则会登录不成功;下面的红色字体分别表示localhost(数据库所在的ip地址),ftpserver(数据库名称),root(连接数据库的用户名),123456(连接数据库密码);绿色字体表示使用文件登录,需要注释掉。

增加数据库连接需要使用的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

进入目录apache-ftpserver-1.0.6,启动服务:sh bin/ftpd.sh res/conf/ftpd-db.xml

执行:ftp 127.0.0.12121    输入用户和密码:user1  123456

 

你可能感兴趣的:(linux,java)