这一段时间项目中需要使用FTP进行文件的下载和传输,然后选定了Apache 的FTPserver当服务器端,然后客户端使用commons-net包进行编写。
关于FtpServer的配置(JDK的配置就不多说了,这里我用的是JDK1.6)。
1.FtpServer的下载地址 http://archive.apache.org/dist/mina/ftpserver/1.0.6/ftpserver-1.0.6.zip
这里我使用的1.0.6版本的FtpServer,下载好之后将其解压到自己的目录中。
2.FtpServer的文件配置
在FtpServer的目录/res/conf/下 有ftpd-typical.xml和users.properties两个文件便是我们需要配置的文件
ftpd-typical.xml 里面:
<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="21">
<ssl>
<keystore file="./res/ftpserver.jks" password="password" />
</ssl>
</nio-listener>
</listeners>
<file-user-manager file="./res/conf/users.properties" />
</server>
其中里面说的很详细了,端口是默认的21端口,然后关于访问者的配置在user.properties中。里面的含义在apache官网的document中说的很详细了。具体的可以去查询apache官网。
users.properties里面:
#密码为空
tpserver.user.hly.userpassword=1234
#主目录的位置
ftpserver.user.hly.homedirectory=./res/home
#当前用户可用
ftpserver.user.hly.enableflag=true
#具有上传权限
ftpserver.user.hly.writepermission=true
#最大登陆用户数为20
ftpserver.user.hly.maxloginnumber=20
#同IP登陆用户数为2
ftpserver.user.hly.maxloginperip=2
#空闲时间为300秒
ftpserver.user.hly.idletime=300
#上传速率限制为48000字节每秒
ftpserver.user.hly.uploadrate=480000
#下载速率限制为480000字节每秒
ftpserver.user.hly.downloadrate=480000
关于用户的配置
ftpserver.user.xxx.xxxx 第一个xxx就是你自己定的用户名。
比如我想有个hly1用户那么 ftpserver.user.hly1.userpassword=1234
这个配置的意思就是hly1用户然后密码是1234。
对了,文件中的anonymous是匿名用户,默认的是开启的,如果想开启匿名用户的访问。
取消匿名用户ftpserver.user.anonymous.enableflag=false
<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="server"
anon-enabled="false" >
...
</server>
都行
