Home > Mobile >  Android deploy Apache FTPServer access on the computer catalog is empty
Android deploy Apache FTPServer access on the computer catalog is empty

Time:05-21

 package example. Lesson1. Transfer; 

The import androidx. Appcompat. App. AppCompatActivity;
The import androidx. Core. App. ActivityCompat;
The import androidx. Core. App. RemoteInput;

The import android. The Manifest;
import android.content.Context;
Import android. Content. IntentFilter;
The import android. Content. PM. PackageManager;
The import android. Content. Res. Resources;
The import android. Content. Res. Loader. ResourcesLoader;
The import android.net.wifi.WifiInfo;
The import android.net.wifi.WifiManager;
import android.os.Bundle;
The import android. OS. The Environment;
The import android. OS. Stars;
import android.widget.TextView;
import android.widget.Toast;

The import org.apache.commons.net.ftp.FTPClientConfig;
The import org. Apache. Ftpserver. Ftpserver;
The import org. Apache. Ftpserver. FtpServerFactory;
The import org. Apache. Ftpserver. Ftplet. Authority;
The import org. Apache. Ftpserver. Ftplet. DefaultFtplet;
The import org. Apache. Ftpserver. Ftplet. FileSystemFactory;
The import org. Apache. Ftpserver. Ftplet. FileSystemView;
The import org. Apache. Ftpserver. Ftplet. FtpException;
The import org. Apache. Ftpserver. Ftplet. FtpReply;
The import org. Apache. Ftpserver. Ftplet. FtpRequest;
The import org. Apache. Ftpserver. Ftplet. FtpSession;
The import org. Apache. Ftpserver. Ftplet. Ftplet;
The import org. Apache. Ftpserver. Ftplet. FtpletResult;
The import org. Apache. Ftpserver. Ftplet. User;
The import org. Apache. Ftpserver. Ftplet. UserManager;
The import org. Apache. Ftpserver. Listener. ListenerFactory;
The import org. Apache. Ftpserver. Usermanager. PropertiesUserManagerFactory;
The import org. Apache. Ftpserver. Usermanager. Impl. BaseUser;
The import org. Apache. Ftpserver. Usermanager. Impl. WritePermission;
Import org, apache log4j. Lf5. Util. The Resource;

Import the Java. IO. FileOutputStream;
Import the Java. IO. IOException;
The import java.net.InetAddress;
The import java.net.NetworkInterface;
The import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Public class MainActivity extends AppCompatActivity {
Private FtpServer mFtpServer=null;
Private String intToIp (int I) {

Return (I & amp; 0 XFF) + "+"
((I & gt;> 8) & amp; 0 XFF) + "+"
((I & gt;> 16) & amp; 0 XFF) + "+"
(I & gt;> 24 & amp; 0 XFF);
}
@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
////to get wifi service
//WifiManager WifiManager=(WifiManager) getSystemService (Context. WIFI_SERVICE);
////whether wifi open
//if (! WifiManager. IsWifiEnabled ()) {
//wifiManager setWifiEnabled (true);
//}
.//WifiInfo WifiInfo=wifiManager getConnectionInfo ();
//int ipAddress.=wifiInfo getIpAddress ();
//String IP=intToIp (ipAddress);
//Toast. MakeText (MainActivity. This IP, Toast. LENGTH_SHORT), show ();
//the new Thread (new Runnable () {
//@ Override
//public void the run () {
//
//try {
//stars. Prepare ();
//InetAddress. GetLocalHost (.) getHostAddress ();
//Toast. MakeText (MainActivity. This InetAddress. GetLocalHost () getHostAddress (), Toast. LENGTH_SHORT), show ();
Toast. MakeText (MainActivity. This getLocalIpAddress (), Toast. LENGTH_SHORT), show ();
//stars. The loop ();
//} the catch (UnknownHostException e) {
//e.p rintStackTrace ();
//}
//}
//}). The start ();
Try {
StartFtpServer (getLocalIpAddress ());
} the catch (IOException e) {
e.printStackTrace();
}
}
Public String getLocalIpAddress () {
Try {
List Interfaces=Collections. The list (NetworkInterface. GetNetworkInterfaces ());
For (NetworkInterface NetworkInterface: interfaces) {
List Addresses=Collections. The list (networkInterface. GetInetAddresses ());

For (InetAddress address: addresses) {
if(! Address. IsLoopbackAddress ()) {
String strAddress=address. GetHostAddress (). ToUpperCase ();
Boolean isIPv4=isIPv4 (strAddress);
If (isIPv4) return strAddress;
}
}
}
} the catch (Exception e) {
e.printStackTrace();
}
return null;
}

Private Boolean Isipv4 (String ipv4) {
//the string is null or empty string
If (ipv4==null | | ipv4. The length ()==0) return false.
//regular segmentation
String [] parts=ipv4. Split (" \ \ ");
If (parts length!=4) return false.
For (String parts: parts) {
Try {
Int n=Integer. ParseInt (part);
//is beyond the scope of right
If (n & lt; 0 | | n & gt; 255) return false.
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related