日期:2014-05-16 浏览次数:20990 次
commons-net-ftp-2.0.jar ftpserver-core-1.0.6.jar log4j-1.2.14.jar mina-core-2.0.4.jar slf4j-api-1.5.2.jar slf4j-log4j12-1.5.2.jar
package com.orgcent.ftp; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.FtpException; import org.apache.ftpserver.listener.ListenerFactory; import android.app.Activity; import android.os.Bundle; public class FtpServerActivity extends Activity { static { //由于Android系统版本原因,有些对ipv6支持存在bug,相关异常看文章底部介绍 System.setProperty("java.net.preferIPv6Addresses", "false"); } private FtpServer mFtpServer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); startFtpServer(); } private void startFtpServer() { FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); //这段很重要,是增加用户配置文件的,网上其它的文章里都没写这段,所以根本登录不上,加上这段就可以登录上了 PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); File files=new File("/mnt/sdcard/users.properties"); userManagerFactory.setFile(files); serverFactory.setUserManager(userManagerFactory.createUserManager()); // set the port of the listener int port = 2221; factory.setPort(port); // replace the default listener serverFactory.addListener("default", factory.createListener()); // start the server FtpServer server = serverFactory.createServer(); this.mFtpServer = server; try { server.start(); } catch (FtpException e) { e.printStackTrace(); } } @Override protected void onDestroy() { super.onDestroy(); if(null != mFtpServer) { mFtpServer.stop(); mFtpServer = null; } } }
#开启admin帐户 # Password is "admin" ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3 #ftp共享目录 ftpserver.user.admin.homedirectory=/mnt/sdcard #是否启用 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 #开启anonymous帐号,不用密码,直接能登录 ftpserver.user.anonymous.userpassword= ftpserver.user.anonymous.homedirectory=/mnt/sdcard 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 ftpserver.user.anonymous.downloadrate=4800