http://www.2cto.com/kf/201501/374048.html
http://blog.csdn.net/smile3670/article/details/44343617 有demo
http://blog.csdn.net/newrocky/article/details/207691 web页通过自写FTP组件上传文件
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..”按钮在弹出的界面中随便起一个名字,点击“确定”这里注意的问题如下图所示,否则有时会有无穷无尽的麻烦
5,点击“Add jars”按钮选择第三方jar包
创建完的项目结构如下
当然每个人开发环境不尽相同,有时别人有用的方法自己不一定有用,这需要自己去探索解决。
关于项目中引用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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
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<networkinterface> en = NetworkInterface // .getNetworkInterfaces(); en.hasMoreElements();) { // NetworkInterface intf = en.nextElement(); // for (Enumeration<inetaddress> 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<string, object= "" >> getData() {
List<map<string, object= "" >> list = new ArrayList<map<string, object= "" >>();
Map<string, object= "" > map = new HashMap<string, object= "" >();
map.put(name, archlinux);
map.put(img, R.drawable.arch);
list.add(map);
map = new HashMap<string, object= "" >();
map.put(name, dentos);
map.put(img, R.drawable.centos);
list.add(map);
map = new HashMap<string, object= "" >();
map.put(name, deepin);
map.put(img, R.drawable.deepin);
list.add(map);
map = new HashMap<string, object= "" >();
map.put(name, fedora);
map.put(img, R.drawable.fedora);
list.add(map);
map = new HashMap<string, object= "" >();
map.put(name, gentoo);
map.put(img, R.drawable.gentoo);
list.add(map);
map = new HashMap<string, object= "" >();
map.put(name, opensuse);
map.put(img, R.drawable.opensuse);
list.add(map);
map = new HashMap<string, object= "" >();
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,></string,></string,></string,></string,></string,></string,></string,></map<string,></map<string,></map<string,></inetaddress></networkinterface> |
String.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
|
<!--?xml version= 1.0 encoding=utf- 8 ?-->
<resources> <string name= "app_name" >AndroidFtp</string>
<string name= "action_settings" >Settings</string>
<string name= "hello_world" >Hello world!</string>
<string name= "ubuntuscr" >#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
</string> <string name= "archlinux" >#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
</string> <string name= "centos" >#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
</string> <string name= "deepin" >#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
</string> <string name= "fedora" >#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
</string> <string name= "gentoo" >#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/
</string> <string name= "opensuse" ></string>
<string name= "users" >
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
</string> </resources> |
以上是主要代码,参考自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的配置文件,当然没有话程序也可以跑,只是会出现一些警告信息而且没有日志记录。
1
2
3
4
5
6
7
|
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、设置匿名用户及对应的服务器文件夹
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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权限是只读的,也就是也可查看文件,但是不能增删改。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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();
}</authority></authority> |
加入可写的权限,此时就能对FTP服务器上的文件进行增删改了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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,必须输入正确的用户名密码。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 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加密的。其他配置项也很好理解。