26, Android running Apache FTP Service

Source: Internet
Author: User
Tags md5 encryption

First, why

Running FTP service on Android device, convenient to view the log on the spot, is so used now.

Second, the premise:

Download Dependency Pack from Apache's official website: http://mina.apache.org/ftpserver-project/download_1.0.6.html

After decompression, the following:

In the list of the right-most jar packages, it is not necessary to import all of our projects, the packages that need to be imported are:

Remember to add the jar package to BuildPath and select the jar package that you added in the Order and export option

Third, how to use:

1  PackageCom.example.zzk;2 3 ImportJava.io.File;4 Importjava.io.IOException;5 6 ImportOrg.apache.ftpserver.FtpServer;7 Importorg.apache.ftpserver.FtpServerFactory;8 Importorg.apache.ftpserver.ftplet.FtpException;9 Importorg.apache.ftpserver.listener.ListenerFactory;Ten Importorg.apache.ftpserver.usermanager.PropertiesUserManagerFactory; One  A  - Importandroid.app.Activity; - ImportAndroid.content.Context; the ImportAndroid.os.Bundle; - Importandroid.os.Environment; - ImportAndroid.view.Menu; - ImportAndroid.view.MenuItem; +  -  Public classMainactivityextendsActivity { +  A      Public StaticString path = environment.getexternalstoragedirectory () +file.separator+ "Ftp_test" +File.separator; at      PublicContext ctxt; -      PublicString tag = "Zzk"; -      Public Staticftpserver Ftpserver; -      - @Override -     protected voidonCreate (Bundle savedinstancestate) { in         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); to          +Ctxt =Getapplicationcontext (); - Ftpservicestart (ctxt); the     }  *      $     Panax Notoginseng      /** -       *  the * Start the FTP service +       */ A       Public Static voidFtpservicestart (Context ctxt) the      { +Ftpserverfactory serverfactory =Newftpserverfactory (); -           $Listenerfactory factory =Newlistenerfactory (); $           -Factory.setport (12345);//set the port of the listener -          theFIleUtils fu =NewFIleUtils (ctxt); -         Try {WuyiFile File =NewFile (path); the                 if(!file.isdirectory ()) -                 { Wu File.mkdir (); -                 } AboutFu.createfile (path+ "Ftpserver.properties"); $String str = "" + -"Ftpserver.user.admin.username=admin\n" + -"Ftpserver.user.admin.userpassword=bff4d7685c1475b68c016c478a728b6e\n" + -"Ftpserver.user.admin.homedirectory=/mnt/sdcard\n" + A"Ftpserver.user.admin.enableflag=true\n" + +"Ftpserver.user.admin.writepermission=true\n" + the"Ftpserver.user.admin.maxloginnumber=250\n" + -"Ftpserver.user.admin.maxloginperip=250\n" + $"Ftpserver.user.admin.idletime=300\n" + the"Ftpserver.user.admin.uploadrate=10000\n" + the"Ftpserver.user.admin.downloadrate=10000\n"; the                                  theFu.writefile (str, path+ "Ftpserver.properties"); -              inFile files=NewFile (path+ "Ftpserver.properties"); the              thePropertiesusermanagerfactory usermanagerfactory =Newpropertiesusermanagerfactory (); About usermanagerfactory.setfile (files); the Serverfactory.setusermanager (Usermanagerfactory.createusermanager ()); the              the}Catch(IOException E1) { +             //TODO auto-generated Catch block - e1.printstacktrace (); the         }Bayi          the           the           -           -           theServerfactory.addlistener ("Default", Factory.createlistener ());//Replace the default listener the          if(Ftpserver! =NULL) the          { the ftpserver.stop (); -          } the           theFtpserver Server =serverfactory.createserver (); theFtpserver =server;94          //Start the server the          Try { the Server.start (); the}Catch(ftpexception e) {98             //TODO auto-generated Catch block About e.printstacktrace (); -         } 101         102      }103 104      the}
View Code

Iv. Summary

1, the general process is:

① Creating an FTP server factory

② Creating an FTP listener factory

③ Setting the Listening port (12345 is set here)

④ Creating an FTP configuration file

1String str = "" +2"Ftpserver.user.admin.username=admin\n" +3"Ftpserver.user.admin.userpassword=bff4d7685c1475b68c016c478a728b6e\n" +4"Ftpserver.user.admin.homedirectory=/mnt/sdcard\n" +5"Ftpserver.user.admin.enableflag=true\n" +6"Ftpserver.user.admin.writepermission=true\n" +7"Ftpserver.user.admin.maxloginnumber=250\n" +8"Ftpserver.user.admin.maxloginperip=250\n" +9"Ftpserver.user.admin.idletime=300\n" +Ten"Ftpserver.user.admin.uploadrate=10000\n" + One"Ftpserver.user.admin.downloadrate=10000\n";

Here the configuration is: the user named Admin password for a string of MD5 encryption (you can set your own, Baidu MD5 encryption, find it yourself), there are set login, IP, up and down the speed of the line, etc.

⑤ The configuration file takes effect

⑥ setting the listening port on the FTP service

⑦ Creating Ftpserver

⑧ Start Service

D. Demo Address

Http://pan.baidu.com/s/1qWA04Ja

V. How to determine if the FTP service started successfully

A handy tool: Chrome, direct input ftp://+ your FTP address +:+ port (example: ftp://192.168.1.2:12345)

26, Android running Apache FTP Service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.