ftp服务器简单介绍:FTP(File Transfer Protocol)是文件传输协议的简称。
作用:让用户连接上一个远程计算机(该计算机上运行着FTP服务器程序)察看远程计算机有哪些文件,然后把文件从远程计算机上拷到本地计算机,或把本地计算机的文件送到远程计算机去。
Apache 官网ftpserver有详细介绍和使用说明以及必要文件下载:www.2cto.com
首先要阅读官网上的介绍,并下载相应资源包。
注意不要下载apache-mina的资源包,而要下载ftpserver-1.0.X资源包。
根据官网“Embedding FtpServer in 5 minutes”中提示,导入相应的资源包。
导入包的步骤参考:
方法是: 1,右键工程,Build path,java build path,
2,选择libraries在右边的按钮中点击“Add Library”
3,选择“User library”,点击“下一步”
4,点击“User librarys”按钮在出现的界面中点击“New..”按钮在弹出的界面中随便起一个名字,点击“确定”这里注意的问题如下图所示,否则有时会有无穷无尽的麻烦
![\](http://www.2cto.com/uploadfile/Collfiles/20150130/2015013008345640.jpg)
5,点击“Add jars”按钮选择第三方jar包
创建完的项目结构如下
![\](http://www.2cto.com/uploadfile/Collfiles/20150130/2015013008345941.jpg)
当然每个人开发环境不尽相同,有时别人有用的方法自己不一定有用,这需要自己去探索解决。
关于项目中引用jar包,相依赖的包名如下(官方介绍参考:http://mina.apache.org/ftpserver-project/embedding_ftpserver.html):
mina-core, 2.0-M3 or later
slf4j-api
ftplet-api
ftpserver-core
实际使用的jar包包括:
slf4j-log4j12-1.5.2.jar
slf4j-api-1.5.2.jar
mina-core-2.0.4.jar
log4j-1.2.14.jar
ftpserver-core-1.0.6.jar
将上述包成功导入是成功的开始,也是可以继续进行的必要条件。
主要代码如下:
MainActivity.java
public class MainActivity extends Activity {
static { // 由于Android系统版本原因,有些对ipv6支持存在bug
System.setProperty(java.net.preferIPv6Addresses, false);
}
private ListView scrList = null;
public static String hostip; // 本机IP
public static String hostmac; // 本机MAC
@SuppressLint(SdCardPath)
//ftp用户配置文件路径
private String filename = /mnt/sdcard/users.properties;
//sd卡目录
private String dirname=/mnt/sdcard/;
@Override
protected void onCreate(Bundle savedInstanceState) {
System.setProperty(java.net.preferIPv6Addresses, false);
super.onCreate(savedInstanceState);
try {
creatDirsFiles();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setContentView(R.layout.activity_main);
scrList = (ListView) findViewById(R.id.scrList);
SimpleAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.list_item, new String[] { name, img }, new int[] {
R.id.nametxtView, R.id.img });
scrList.setAdapter(adapter);
scrList.setOnItemClickListener(itemlistener);
hostip = getLocalIpAddress();
hostmac = getLocalMacAddress();
this.setTitle(ftp:// + hostip + :2221/);
startFtpServer();
}
private void creatDirsFiles() throws IOException {
// TODO Auto-generated method stub
String tmp=getString(R.string.archlinux);
isFolderExists(dirname);
isFolderExists(dirname+archlinux/);
File sourceFile = new File(dirname+archlinux+/sources.list);
FileOutputStream fos=null;
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
isFolderExists(dirname+centos/);
tmp=getString(R.string.centos);
sourceFile=new File(dirname+centos+/sources.list);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
isFolderExists(dirname+deepin/);
tmp=getString(R.string.deepin);
sourceFile=new File(dirname+deepin+/sources.list);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
isFolderExists(dirname+fedora/);
tmp=getString(R.string.fedora);
sourceFile=new File(dirname+fedora+/sources.list);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
isFolderExists(dirname+gentoo/);
tmp=getString(R.string.gentoo);
sourceFile=new File(dirname+gentoo+/sources.list);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
isFolderExists(dirname+opensuse/);
tmp=getString(R.string.ubuntuscr);
sourceFile=new File(dirname+opensuse+/sources.list);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
isFolderExists(dirname+ubuntu/);
tmp=getString(R.string.ubuntuscr);
sourceFile=new File(dirname+ubuntu+/sources.list);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
tmp=getString(R.string.users);
sourceFile=new File(dirname+/users.properties);
try {
fos = new FileOutputStream(sourceFile);
fos.write(tmp.getBytes());
} catch (FileNotFoundException e) {
}
fos.close();
}
OnItemClickListener itemlistener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position,
long id) {
// TODO Auto-generated method stub
TextView nametxtView = (TextView) view
.findViewById(R.id.nametxtView);
String name = ftp:// + hostip + :2221/
+ (String) nametxtView.getText() + /;
Bundle bundle = new Bundle();
bundle.putString(name, name);
Intent intent = new Intent(MainActivity.this, Downloadaddress.class);
intent.putExtras(bundle);
startActivity(intent);
}
};
private void startFtpServer() {
FtpServerFactory serverFactory = new FtpServerFactory();
System.out.println(Factory创建);
ListenerFactory factory = new ListenerFactory();
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
File files = new File(filename);
userManagerFactory.setFile(files);
serverFactory.setUserManager(userManagerFactory.createUserManager());
System.out.println(serverFactory.getFileSystem());
// 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();
try {
server.start();
} catch (FtpException e) {
System.out.println(e);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public String getLocalIpAddress() {
// try {
// for (Enumeration en = NetworkInterface
// .getNetworkInterfaces(); en.hasMoreElements();) {
// NetworkInterface intf = en.nextElement();
// for (Enumeration enumIpAddr = intf
// .getInetAddresses(); enumIpAddr.hasMoreElements();) {
// InetAddress inetAddress = enumIpAddr.nextElement();
// if (!inetAddress.isLoopbackAddress()) {
// return inetAddress.getHostAddress().toString();
// }
// }
// }
// } catch (SocketException ex) {
// Log.e(WifiPreference IpAddress, ex.toString());
// }
// return null;
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
int ip = wifiManager.getConnectionInfo().getIpAddress();
String realIp = intToIp(ip);
return realIp;
}
public String intToIp(int i) {
return (i & 0xFF ) + . + ((i >> 8 ) & 0xFF) + . + ((i >> 16 ) & 0xFF) + . + ( i >> 24 & 0xFF) ;
}
public String getLocalMacAddress() {
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}
private List<map> getData() {
List<map> list = new ArrayList<map>();
Map map = new HashMap();
map.put(name, archlinux);
map.put(img, R.drawable.arch);
list.add(map);
map = new HashMap();
map.put(name, dentos);
map.put(img, R.drawable.centos);
list.add(map);
map = new HashMap();
map.put(name, deepin);
map.put(img, R.drawable.deepin);
list.add(map);
map = new HashMap();
map.put(name, fedora);
map.put(img, R.drawable.fedora);
list.add(map);
map = new HashMap();
map.put(name, gentoo);
map.put(img, R.drawable.gentoo);
list.add(map);
map = new HashMap();
map.put(name, opensuse);
map.put(img, R.drawable.opensuse);
list.add(map);
map = new HashMap();
map.put(name, ubuntu);
map.put(img, R.drawable.ubuntu);
list.add(map);
return list;
}
boolean isFolderExists(String strFolder) {
File file = new File(strFolder);
if (!file.exists()) {
if (file.mkdirs()) {
return true;
} else
return false;
}
return true;
}
}
String.xml
AndroidFtp
Settings
Hello world!
#Welcome to LZUOSS Mirror Website
#
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:
#Email:oss.lzu.edu.cn@gmail.com
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)
#QQ Group:247736999
#
#Our Website:http://oss.lzu.edu.cn
#Our Mirror:http://mirror.lzu.edu.cn
#Our Project Center(GIT):http://oss.lzu.edu.cn/project
#Our Blog:http://oss.lzu.edu.cn/blog
#
#
#
#Back up your files before any change
#Rename this file to sources.list(without quotation marks)
#Put this file in /etc/apt/sources.list
#ubuntu12.04
deb http://mirror.lzu.edu.cn/ubuntu/ precise main restricted universe multiverse
deb http://mirror.lzu.edu.cn/ubuntu/ precise-security main restricted universe multiverse
deb http://mirror.lzu.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirror.lzu.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirror.lzu.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
#ubuntu12.10
#网易的源(163源,无论是不是教育网,速度都很快)
#deb http://mirrors.163.com/ubuntu/ quantal main universe restricted multiverse
#deb-src http://mirrors.163.com/ubuntu/ quantal main universe restricted multiverse
#deb http://mirrors.163.com/ubuntu/ quantal-security universe main multiverse restricted
#deb-src http://mirrors.163.com/ubuntu/ quantal-security universe main multiverse restricted
#deb http://mirrors.163.com/ubuntu/ quantal-updates universe main multiverse restricted
#deb http://mirrors.163.com/ubuntu/ quantal-proposed universe main multiverse restricted
#deb-src http://mirrors.163.com/ubuntu/ quantal-proposed universe main multiverse restricted
#deb http://mirrors.163.com/ubuntu/ quantal-backports universe main multiverse restricted
#deb-src http://mirrors.163.com/ubuntu/ quantal-backports universe main multiverse restricted
#deb-src http://mirrors.163.com/ubuntu/ quantal-updates universe main multiverse restricted
#搜狐的源(sohu 源今天还没有更新,不过应该快了)
#deb http://mirrors.sohu.com/ubuntu/ quantal main restricted
#deb-src http://mirrors.sohu.com/ubuntu/ quantal main restricted
#deb http://mirrors.sohu.com/ubuntu/ quantal-updates main restricted
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-updates main restricted
#deb http://mirrors.sohu.com/ubuntu/ quantal universe
#deb-src http://mirrors.sohu.com/ubuntu/ quantal universe
#deb http://mirrors.sohu.com/ubuntu/ quantal-updates universe
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-updates universe
#deb http://mirrors.sohu.com/ubuntu/ quantal multiverse
#deb-src http://mirrors.sohu.com/ubuntu/ quantal multiverse
#deb http://mirrors.sohu.com/ubuntu/ quantal-updates multiverse
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-updates multiverse
#deb http://mirrors.sohu.com/ubuntu/ quantal-backports main restricted universe multiverse
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-backports main restricted universe multiverse
#deb http://mirrors.sohu.com/ubuntu/ quantal-security main restricted
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-security main restricted
#deb http://mirrors.sohu.com/ubuntu/ quantal-security universe
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-security universe
#deb http://mirrors.sohu.com/ubuntu/ quantal-security multiverse
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-security multiverse
#deb http://extras.ubuntu.com/ubuntu quantal main
#deb-src http://extras.ubuntu.com/ubuntu quantal main
#台湾源(台湾的ubuntu 更新源还是很给力的)
#deb http://tw.archive.ubuntu.com/ubuntu/ quantal main universe restricted multiverse
#deb-src http://tw.archive.ubuntu.com/ubuntu/ quantal main universe restricted multiverse
#deb http://tw.archive.ubuntu.com/ubuntu/ quantal-security universe main multiverse restricted
#deb-src http://tw.archive.ubuntu.com/ubuntu/ quantal-security universe main multiverse restricted
#deb http://tw.archive.ubuntu.com/ubuntu/ quantal-updates universe main multiverse restricted
#deb-src http://tw.archive.ubuntu.com/ubuntu/ quantal-updates universe main multiverse restricted
#骨头源,骨头源是bones7456架设的一个Ubuntu源 ,提供ubuntu,deepin
#deb http://ubuntu.srt.cn/ubuntu/ quantal main universe restricted multiverse
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal main universe restricted multiverse
#deb http://ubuntu.srt.cn/ubuntu/ quantal-security universe main multiverse restricted
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-security universe main multiverse restricted
#deb http://ubuntu.srt.cn/ubuntu/ quantal-updates universe main multiverse restricted
#deb http://ubuntu.srt.cn/ubuntu/ quantal-proposed universe main multiverse restricted
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-proposed universe main multiverse restricted
#deb http://ubuntu.srt.cn/ubuntu/ quantal-backports universe main multiverse restricted
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-backports universe main multiverse restricted
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-updates universe main multiverse restricted
#ubuntu.cn99.com源(推荐):
#deb http://ubuntu.cn99.com/ubuntu/ quantal main restricted universe multiverse
#deb http://ubuntu.cn99.com/ubuntu/ quantal-updates main restricted universe multiverse
#deb http://ubuntu.cn99.com/ubuntu/ quantal-security main restricted universe multiverse
#deb http://ubuntu.cn99.com/ubuntu/ quantal-backports main restricted universe multiverse
#deb http://ubuntu.cn99.com/ubuntu-cn/ quantal main restricted universe multiverse
#教育网源
#电子科技大学
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal main restricted universe multiverse
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-backports main restricted universe multiverse
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal main restricted universe multiverse
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-backports main restricted universe multiverse
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse
#中国科技大学
#deb http://debian.ustc.edu.cn/ubuntu/ quantal main restricted universe multiverse
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-backports restricted universe multiverse
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal main restricted universe multiverse
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-backports main restricted universe multiverse
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse
#北京理工大学
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe
#兰州大学
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal main multiverse restricted universe
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe
#deb ftp://mirror.lzu.edu.cn/ubuntu-cn/ quantal main multiverse restricted universe
#上海交通大学(上海交大源,教育网的速度不用说了)
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe
#deb http://ftp.sjtu.edu.cn/ubuntu-cn/ quantal main multiverse restricted universe
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe
#Welcome to LZUOSS Mirror Website
#
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:
#Email:oss.lzu.edu.cn@gmail.com
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)
#QQ Group:247736999
#
#Our Website:http://oss.lzu.edu.cn
#Our Mirror:http://mirror.lzu.edu.cn
#Our Project Center(GIT):http://oss.lzu.edu.cn/project
#Our Blog:http://oss.lzu.edu.cn/blog
#
#
#
#Back up your files before any change
#Rename this file to mirrorlist(without quotation marks)
#Put this file in /etc/pacman.d/
#
#
#
#Example
#For i686
Server = http://mirror.lzu.edu.cn/archlinux/$repo/os/i686
#For x86_64
Server = http://mirror.lzu.edu.cn/archlinux/$repo/os/x86_64
#Welcome to LZUOSS Mirror Website
#
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:
#Email:oss.lzu.edu.cn@gmail.com
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)
#QQ Group:247736999
#
#Our Website:http://oss.lzu.edu.cn
#Our Mirror:http://mirror.lzu.edu.cn
#Our Project Center(GIT):http://oss.lzu.edu.cn/project
#Our Blog:http://oss.lzu.edu.cn/blog
#
#
#
#Back up your files before any change
#
#
#For CentOS5 Users
#Create a new file CentOS5-Base-LZUOSS.repo(without quotation marks) with content below:
############START_CENTOS_5
[base]
name=CentOS-$releasever - Base - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#released updates
[updates]
name=CentOS-$releasever - Updates - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/addons/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
############END_CENTOS_5
#And put this file in /etc/yum.repos.d/
#
#
#For CentOS6 Users
#Create a new file CentOS6-Base-LZUOSS.repo(without quotation marks) with content below:
############START_CENTOS_6
[base]
name=CentOS-$releasever - Base - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - LZUOSS
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
############END_CENTOS_6
#And Put this file in /etc/yum.repos.d/
#
#Make cahce use command like this: yum makecache
#Welcome to LZUOSS Mirror Website
#
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:
#Email:oss.lzu.edu.cn@gmail.com
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)
#QQ Group:247736999
#
#Our Website:http://oss.lzu.edu.cn
#Our Mirror:http://mirror.lzu.edu.cn
#Our Project Center(GIT):http://oss.lzu.edu.cn/project
#Our Blog:http://oss.lzu.edu.cn/blog
#
#
#
#Back up your files before any change
#Rename this file to source.list(without quotation marks)
#Put this file in /etc/apt/
#
#
#
deb http://mirror.lzu.edu.cn/ubuntu precise main restricted universe multiverse
deb http://mirror.lzu.edu.cn/ubuntu precise-security main restricted universe multiverse
deb http://mirror.lzu.edu.cn/ubuntu precise-updates main restricted universe multiverse
#deb http://mirror.lzu.edu.cn/ubuntu precise-proposed main restricted universe multiverse
#deb http://mirror.lzu.edu.cn/ubuntu precise-backports main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu precise main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu precise-security main restricted universe multiverse
deb-src http://mirror.lzu.edu.cn/ubuntu precise-updates main restricted universe multiverse
#deb-src http://mirror.lzu.edu.cn/ubuntu precise-proposed main restricted universe multiverse
#deb-src http://mirror.lzu.edu.cn/ubuntu precise-backports main restricted universe multiverse
deb http://mirror.lzu.edu.cn/deepin quantal main non-free
deb-src http://mirror.lzu.edu.cn/deepin quantal main non-free
deb http://mirror.lzu.edu.cn/deepin quantal-updates main non-free
deb-src http://mirror.lzu.edu.cn/deepin quantal-updates main non-free
#Welcome to LZUOSS Mirror Website
#
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:
#Email:oss.lzu.edu.cn@gmail.com
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)
#QQ Group:247736999
#
#Our Website:http://oss.lzu.edu.cn
#Our Mirror:http://mirror.lzu.edu.cn
#Our Project Center(GIT):http://oss.lzu.edu.cn/project
#Our Blog:http://oss.lzu.edu.cn/blog
#
#
#
#Back up your files before any change
#
#Create a new file fedora-LZUOSS.repo(without quotation marks) with content below:
############START_FEDORA_LZUOSS.REPO
[fedora]
name=Fedora $releasever - $basearch - LZUOSS
failovermethod=priority
baseurl=http://mirror.lzu.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
enabled=1
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
[fedora-debuginfo]
name=Fedora $releasever - $basearch - Debug - LZUOSS
failovermethod=priority
baseurl=http://mirror.lzu.edu.cn/fedora/releases/$releasever/Everything/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-debug-$releasever&arch=$basearch
enabled=0
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
[fedora-source]
name=Fedora $releasever - Source - LZUOSS
failovermethod=priority
baseurl=http://mirror.lzu.edu.cn/fedora/releases/$releasever/Everything/source/SRPMS/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-source-$releasever&arch=$basearch
enabled=0
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
############END_FEDORA_LZUOSS.REPO
#And put this file in /etc/yum.repos.d/
#
#Create a new file fedora-updates-LZUOSS.repo(without quotation marks) with content below:
############START_FEDORA_UPDATES_LZUOSS.REPO
[updates]
name=Fedora $releasever - $basearch - Updates - LZUOSS
failovermethod=priority
baseurl=http://mirror.lzu.edu.cn/fedora/updates/$releasever/$basearch/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
[updates-debuginfo]
name=Fedora $releasever - $basearch - Updates - Debug - LZUOSS
failovermethod=priority
baseurl=http://mirror.lzu.edu.cn/fedora/updates/$releasever/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f$releasever&arch=$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
[updates-source]
name=Fedora $releasever - Updates Source - LZUOSS
failovermethod=priority
baseurl=http://mirror.lzu.edu.cn/fedora/updates/$releasever/SRPMS/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f$releasever&arch=$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
############END_FEDORA_UPDATES_LZUOSS.REPO
#And put this file in /etc/yum.repos.d/
#
#Make cahce use command like this: yum makecache
#Welcome to LZUOSS Mirror Website
#
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:
#Email:oss.lzu.edu.cn@gmail.com
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)
#QQ Group:247736999
#
#Our Website:http://oss.lzu.edu.cn
#Our Mirror:http://mirror.lzu.edu.cn
#Our Project Center(GIT):http://oss.lzu.edu.cn/project
#Our Blog:http://oss.lzu.edu.cn/blog
#
#
#
#Back up your files before any change
#
#
#Add or update the file in /etc/make.conf with the last line
GENTOO_MIRRORS=http://mirror.lzu.edu.cn/gentoo/
ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3
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
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
以上是主要代码,参考自http://www.eoeandroid.com/thread-281101-1-1.html
另外有比较好的参考资料:http://www.tuicool.com/articles/iqE3Ef
Apache FtpServer是一个纯Java实现的FTP服务器,基于大名鼎鼎的网络框架apache MINA实现。它既可以作为一个完整的FTP服务器单独使用,也可以在Java程序中调用,类似于Jetty可以作为嵌入式的HTTP服务器。
下面介绍如何在Java中启动FTP服务器。
Apache FtpServer下载地址,目前最新版是1.0.6:
http://mina.apache.org/ftpserver-project/index.html
解压后在apache-ftpserver-1.0.6commonlib文件夹中添加需要的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
另外,项目中还需要加入log4j的配置文件,当然没有话程序也可以跑,只是会出现一些警告信息而且没有日志记录。
public static void main(String[] args) throws FtpException {
FtpServerFactory serverFactory = new FtpServerFactory();
FtpServer server = serverFactory.createServer();
server.start();
}
这是最简单的FTP服务器。运行程序,启动FTP服务器后,在地址栏中输入ftp://localhost,可以看到以下界面,要求输入用户名密码。当然这个FTP是进不去的,因为它是最简单的FTP服务器,简单到没有用户。
2、设置匿名用户及对应的服务器文件夹
public static void main(String[] args) throws FtpException {
FtpServerFactory serverFactory = new FtpServerFactory();
BaseUser user = new BaseUser();
user.setName(anonymous);
user.setHomeDirectory(D:/test);
serverFactory.getUserManager().save(user);
FtpServer server = serverFactory.createServer();
server.start();
}
添加一个匿名用户anonymous,并设置它对应的文件夹是D:/test。再次进入ftp://localhost,可以看到D:/test中的文件。但是此时的FTP权限是只读的,也就是也可查看文件,但是不能增删改。
public static void main(String[] args) throws FtpException {
FtpServerFactory serverFactory = new FtpServerFactory();
BaseUser user = new BaseUser();
user.setName(anonymous);
user.setHomeDirectory(D:/test);
List authorities = new ArrayList();
authorities.add(new WritePermission());
user.setAuthorities(authorities);
serverFactory.getUserManager().save(user);
FtpServer server = serverFactory.createServer();
server.start();
}
加入可写的权限,此时就能对FTP服务器上的文件进行增删改了。
public static void main(String[] args) throws FtpException {
FtpServerFactory serverFactory = new FtpServerFactory();
BaseUser user = new BaseUser();
user.setName(test);
user.setPassword(123456);
user.setHomeDirectory(D:/test);
serverFactory.getUserManager().save(user);
FtpServer server = serverFactory.createServer();
server.start();
}
添加用户test,密码是123456,此时客户端要想进入ftp,必须输入正确的用户名密码。
public static void main(String[] args) throws FtpException {
FtpServerFactory serverFactory = new FtpServerFactory();
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(new File(users.properties));
serverFactory.setUserManager(userManagerFactory.createUserManager());
FtpServer server = serverFactory.createServer();
server.start();
}
配置文件users.properties:
# Password is admin
ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3
ftpserver.user.admin.homedirectory=D:/test
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=D:/test
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
这是通过配置文件users.properties设置用户。配置文件中包含两个用户:匿名用户anonymous和admin。anonymous只有只读权限,admin有可写权限。其中userpassword配置项是
MD5
加密
的。其他配置项也很好理解。