2019-12-13 16:59:18 printf123scanf 阅读数 43

虽然网上也有挺多的教程,我可能就是自己mark一下,对你们有帮助就更好🙂

先看效果

电脑端使用xshell连接Android服务器
在这里插入图片描述

手机使用JuiceSSH连Android服务器
在这里插入图片描述

Android手机前期准备

《一个重要的大前提就是:你的服务器手机必须拥有root权限》

至于权限怎么获得,自行解决,现在Android版本越高,对隐私就越看重,当然就不太随意直接给你危险权限,Android10就更注重隐私和安全

若是在window上登录搭建好的Android服务器,需要下载xshell
若是在另外一部手机上登陆搭建好的Android服务器,需要下载安装JuiceSSH

  1. 豌豆荚上面下载 jUiceSSH(这个软件安装在另外一部需要登录到服务器的手机) 和 Linux Deploy
  2. 这里下载BusyBox,选择下面Assets的apk下载
    在这里插入图片描述

搭建步骤

先是准备好BusyBox

  1. 打开busybox,进入左边的设置,记住install path,因为等下需要在Linux deploy上填写该路径
    在这里插入图片描述
  2. 点击install,等待done
    在这里插入图片描述
    这个就好了,下一个

先设置参数,再安装

  1. 打开首页底栏最右边那个按钮,该打勾的要打勾(这是我的配置), PATH变量填写上一个软件busybox install path的值,这个很重要哦
    在这里插入图片描述

  2. 记得勾选启用SSH,其余默认就好,密码自行更改

在这里插入图片描述

  1. 先安装,再配置 (安装估计得等半小时,开局王者,中间可能要确认y,不太记得了)

在这里插入图片描述

  1. 启动和关闭,显示done就是成功了,就去登录把
    在这里插入图片描述
最后我犯了一个弱智错误,以至于我耗费了挺多时间

什么错误呢?
看到懂这个登陆格式来吧?
我就错在这,格式写错了,那当然是登陆不进去
在这里插入图片描述

正确格式(当然,还有另外一种格式,自己往回看咯)
在这里插入图片描述

2015-01-29 16:29:45 adayabetter 阅读数 4544

 ftp服务器简单介绍:FTP(File Transfer Protocol)是文件传输协议的简称。

作用:让用户连接上一个远程计算机(该计算机上运行着FTP服务器程序)察看远程计算机有哪些文件,然后把文件从远程计算机上拷到本地计算机,或把本地计算机的文件送到远程计算机去。

Apache 官网ftpserver有详细介绍和使用说明以及必要文件下载:http://mina.apache.org/ftpserver-project/embedding_ftpserver.html

首先要阅读官网上的介绍,并下载相应资源包。

ftpserver下载地址:http://mina.apache.org/downloads-ftpserver.html

注意不要下载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

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.xml

 

<?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\r\n
#\r\n
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:\r\n
#Email:oss.lzu.edu.cn@gmail.com\r\n
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)\r\n
#QQ Group:247736999\r\n
#\r\n
#Our Website:http://oss.lzu.edu.cn\r\n
#Our Mirror:http://mirror.lzu.edu.cn\r\n
#Our Project Center(GIT):http://oss.lzu.edu.cn/project\r\n
#Our Blog:http://oss.lzu.edu.cn/blog\r\n
#\r\n
#\r\n
#\r\n
#Back up your files before any change\r\n
#Rename this file to "sources.list"(without quotation marks)\r\n
#Put this file in /etc/apt/sources.list\r\n
#ubuntu12.04\r\n
deb http://mirror.lzu.edu.cn/ubuntu/ precise main restricted universe multiverse\r\n
deb http://mirror.lzu.edu.cn/ubuntu/ precise-security main restricted universe multiverse\r\n
deb http://mirror.lzu.edu.cn/ubuntu/ precise-updates main restricted universe multiverse\r\n
deb http://mirror.lzu.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse\r\n
deb http://mirror.lzu.edu.cn/ubuntu/ precise-backports main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-security main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-updates main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu/ precise-backports main restricted universe multiverse\r\n
#ubuntu12.10\r\n
#网易的源(163源,无论是不是教育网,速度都很快)\r\n
#deb http://mirrors.163.com/ubuntu/ quantal main universe restricted multiverse\r\n
#deb-src http://mirrors.163.com/ubuntu/ quantal main universe restricted multiverse\r\n
#deb http://mirrors.163.com/ubuntu/ quantal-security universe main multiverse restricted\r\n
#deb-src http://mirrors.163.com/ubuntu/ quantal-security universe main multiverse restricted\r\n
#deb http://mirrors.163.com/ubuntu/ quantal-updates universe main multiverse restricted\r\n
#deb http://mirrors.163.com/ubuntu/ quantal-proposed universe main multiverse restricted\r\n
#deb-src http://mirrors.163.com/ubuntu/ quantal-proposed universe main multiverse restricted\r\n
#deb http://mirrors.163.com/ubuntu/ quantal-backports universe main multiverse restricted\r\n
#deb-src http://mirrors.163.com/ubuntu/ quantal-backports universe main multiverse restricted\r\n
#deb-src http://mirrors.163.com/ubuntu/ quantal-updates universe main multiverse restricted\r\n
\r\n
#搜狐的源(sohu 源今天还没有更新,不过应该快了)\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal main restricted\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal main restricted\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-updates main restricted\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-updates main restricted\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal universe\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal universe\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-updates universe\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-updates universe\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal multiverse\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal multiverse\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-updates multiverse\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-updates multiverse\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-backports main restricted universe multiverse\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-backports main restricted universe multiverse\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-security main restricted\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-security main restricted\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-security universe\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-security universe\r\n
#deb http://mirrors.sohu.com/ubuntu/ quantal-security multiverse\r\n
#deb-src http://mirrors.sohu.com/ubuntu/ quantal-security multiverse\r\n
#deb http://extras.ubuntu.com/ubuntu quantal main\r\n
#deb-src http://extras.ubuntu.com/ubuntu quantal main
\r\n
#台湾源(台湾的ubuntu 更新源还是很给力的)\r\n
#deb http://tw.archive.ubuntu.com/ubuntu/ quantal main universe restricted multiverse\r\n
#deb-src http://tw.archive.ubuntu.com/ubuntu/ quantal main universe restricted multiverse\r\n
#deb http://tw.archive.ubuntu.com/ubuntu/ quantal-security universe main multiverse restricted\r\n
#deb-src http://tw.archive.ubuntu.com/ubuntu/ quantal-security universe main multiverse restricted\r\n
#deb http://tw.archive.ubuntu.com/ubuntu/ quantal-updates universe main multiverse restricted\r\n
#deb-src http://tw.archive.ubuntu.com/ubuntu/ quantal-updates universe main multiverse restricted\r\n
\r\n
#骨头源,骨头源是bones7456架设的一个Ubuntu源 ,提供ubuntu,deepin\r\n
#deb http://ubuntu.srt.cn/ubuntu/ quantal main universe restricted multiverse\r\n
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal main universe restricted multiverse\r\n
#deb http://ubuntu.srt.cn/ubuntu/ quantal-security universe main multiverse restricted\r\n
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-security universe main multiverse restricted\r\n
#deb http://ubuntu.srt.cn/ubuntu/ quantal-updates universe main multiverse restricted\r\n
#deb http://ubuntu.srt.cn/ubuntu/ quantal-proposed universe main multiverse restricted\r\n
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-proposed universe main multiverse restricted\r\n
#deb http://ubuntu.srt.cn/ubuntu/ quantal-backports universe main multiverse restricted\r\n
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-backports universe main multiverse restricted\r\n
#deb-src http://ubuntu.srt.cn/ubuntu/ quantal-updates universe main multiverse restricted\r\n
\r\n
#ubuntu.cn99.com源(推荐):\r\n
#deb http://ubuntu.cn99.com/ubuntu/ quantal main restricted universe multiverse\r\n
#deb http://ubuntu.cn99.com/ubuntu/ quantal-updates main restricted universe multiverse\r\n
#deb http://ubuntu.cn99.com/ubuntu/ quantal-security main restricted universe multiverse\r\n
#deb http://ubuntu.cn99.com/ubuntu/ quantal-backports main restricted universe multiverse\r\n
#deb http://ubuntu.cn99.com/ubuntu-cn/ quantal main restricted universe multiverse\r\n
\r\n
#教育网源\r\n
#电子科技大学\r\n
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal main restricted universe multiverse\r\n
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-backports main restricted universe multiverse\r\n
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse\r\n
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse\r\n
#deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse\r\n
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal main restricted universe multiverse\r\n
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-backports main restricted universe multiverse\r\n
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse\r\n
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse\r\n
#deb-src http://ubuntu.uestc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse\r\n
\r\n
#中国科技大学\r\n
#deb http://debian.ustc.edu.cn/ubuntu/ quantal main restricted universe multiverse\r\n
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-backports restricted universe multiverse\r\n
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse\r\n
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse\r\n
#deb http://debian.ustc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse\r\n
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal main restricted universe multiverse\r\n
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-backports main restricted universe multiverse\r\n
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-proposed main restricted universe multiverse\r\n
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-security main restricted universe multiverse\r\n
#deb-src http://debian.ustc.edu.cn/ubuntu/ quantal-updates main restricted universe multiverse\r\n
#北京理工大学\r\n
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe\r\n
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe\r\n
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe\r\n
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe\r\n
#deb http://mirror.bjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe\r\n
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe\r\n
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe\r\n
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe\r\n
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe\r\n
#deb-src http://mirror.bjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe\r\n
\r\n
#兰州大学\r\n
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal main multiverse restricted universe\r\n
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe\r\n
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe\r\n
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe\r\n
#deb ftp://mirror.lzu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe\r\n
#deb ftp://mirror.lzu.edu.cn/ubuntu-cn/ quantal main multiverse restricted universe\r\n
\r\n
#上海交通大学(上海交大源,教育网的速度不用说了)\r\n
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe\r\n
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe\r\n
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe\r\n
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe\r\n
#deb http://ftp.sjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe\r\n
#deb http://ftp.sjtu.edu.cn/ubuntu-cn/ quantal main multiverse restricted universe\r\n
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal main multiverse restricted universe\r\n
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-backports main multiverse restricted universe\r\n
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-proposed main multiverse restricted universe\r\n
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-security main multiverse restricted universe\r\n
#deb-src http://ftp.sjtu.edu.cn/ubuntu/ quantal-updates main multiverse restricted universe\r\n
</string>
<string name="archlinux">#Welcome to LZUOSS Mirror Website\r\n
#\r\n
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:\r\n
#Email:oss.lzu.edu.cn@gmail.com\r\n
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)\r\n
#QQ Group:247736999\r\n
#\r\n
#Our Website:http://oss.lzu.edu.cn\r\n
#Our Mirror:http://mirror.lzu.edu.cn\r\n
#Our Project Center(GIT):http://oss.lzu.edu.cn/project\r\n
#Our Blog:http://oss.lzu.edu.cn/blog\r\n
#\r\n
#\r\n
#\r\n
#Back up your files before any change\r\n
#Rename this file to "mirrorlist"(without quotation marks)\r\n
#Put this file in /etc/pacman.d/\r\n
#\r\n
#\r\n
#\r\n
#Example\r\n
#For i686\r\n
Server = http://mirror.lzu.edu.cn/archlinux/$repo/os/i686\r\n
#For x86_64\r\n
Server = http://mirror.lzu.edu.cn/archlinux/$repo/os/x86_64\r\n
</string>
<string name="centos">#Welcome to LZUOSS Mirror Website\r\n
#\r\n
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:\r\n
#Email:oss.lzu.edu.cn@gmail.com\r\n
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)\r\n
#QQ Group:247736999\r\n
#\r\n
#Our Website:http://oss.lzu.edu.cn\r\n
#Our Mirror:http://mirror.lzu.edu.cn\r\n
#Our Project Center(GIT):http://oss.lzu.edu.cn/project\r\n
#Our Blog:http://oss.lzu.edu.cn/blog\r\n
#\r\n
#\r\n
#\r\n
#Back up your files before any change\r\n
#\r\n
#\r\n
#For CentOS5 Users\r\n
#Create a new file "CentOS5-Base-LZUOSS.repo"(without quotation marks) with content below:\r\n
############START_CENTOS_5\r\n
[base]\r\n
name=CentOS-$releasever - Base - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/os/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5\r\n
\r\n
#released updates \r\n
[updates]\r\n
name=CentOS-$releasever - Updates - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/updates/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5\r\n
\r\n
#packages used/produced in the build but not released\r\n
[addons]\r\n
name=CentOS-$releasever - Addons - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/addons/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5\r\n
\r\n
#additional packages that may be useful\r\n
[extras]\r\n
name=CentOS-$releasever - Extras - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/extras/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5\r\n
\r\n
#additional packages that extend functionality of existing packages\r\n
[centosplus]\r\n
name=CentOS-$releasever - Plus - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/centosplus/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus\r\n
gpgcheck=1\r\n
enabled=0\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5\r\n
\r\n
#contrib - packages by Centos Users\r\n
[contrib]\r\n
name=CentOS-$releasever - Contrib - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/contrib/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib\r\n
gpgcheck=1\r\n
enabled=0\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5\r\n
############END_CENTOS_5\r\n
#And put this file in /etc/yum.repos.d/\r\n
#\r\n
#\r\n
#For CentOS6 Users\r\n
#Create a new file "CentOS6-Base-LZUOSS.repo"(without quotation marks) with content below:\r\n
############START_CENTOS_6\r\n
[base]\r\n
name=CentOS-$releasever - Base  - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/os/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6\r\n
\r\n
#released updates \r\n
[updates]\r\n
name=CentOS-$releasever - Updates  - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/updates/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6\r\n
\r\n
#additional packages that may be useful\r\n
[extras]\r\n
name=CentOS-$releasever - Extras  - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/extras/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras\r\n
gpgcheck=1\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6\r\n
\r\n
#additional packages that extend functionality of existing packages\r\n
[centosplus]\r\n
name=CentOS-$releasever - Plus  - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/centosplus/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus\r\n
gpgcheck=1\r\n
enabled=0\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6\r\n
\r\n
#contrib - packages by Centos Users\r\n
[contrib]\r\n
name=CentOS-$releasever - Contrib  - LZUOSS\r\n
baseurl=http://mirror.lzu.edu.cn/centos/$releasever/contrib/$basearch/\r\n
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib\r\n
gpgcheck=1\r\n
enabled=0\r\n
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6\r\n
############END_CENTOS_6\r\n
#And Put this file in /etc/yum.repos.d/\r\n
#\r\n
#Make cahce use command like this: yum makecache\r\n
</string>
<string name="deepin">#Welcome to LZUOSS Mirror Website\r\n
#\r\n
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:\r\n
#Email:oss.lzu.edu.cn@gmail.com\r\n
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)\r\n
#QQ Group:247736999\r\n
#\r\n
#Our Website:http://oss.lzu.edu.cn\r\n
#Our Mirror:http://mirror.lzu.edu.cn\r\n
#Our Project Center(GIT):http://oss.lzu.edu.cn/project\r\n
#Our Blog:http://oss.lzu.edu.cn/blog\r\n
#\r\n
#\r\n
#\r\n
#Back up your files before any change\r\n
#Rename this file to "source.list"(without quotation marks)\r\n
#Put this file in /etc/apt/\r\n
#\r\n
#\r\n
#\r\n
deb http://mirror.lzu.edu.cn/ubuntu precise main restricted universe multiverse\r\n
deb http://mirror.lzu.edu.cn/ubuntu precise-security main restricted universe multiverse\r\n
deb http://mirror.lzu.edu.cn/ubuntu precise-updates main restricted universe multiverse\r\n
#deb http://mirror.lzu.edu.cn/ubuntu precise-proposed main restricted universe multiverse\r\n
#deb http://mirror.lzu.edu.cn/ubuntu precise-backports main restricted universe multiverse\r\n
\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu precise main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu precise-security main restricted universe multiverse\r\n
deb-src http://mirror.lzu.edu.cn/ubuntu precise-updates main restricted universe multiverse\r\n
#deb-src http://mirror.lzu.edu.cn/ubuntu precise-proposed main restricted universe multiverse\r\n
#deb-src http://mirror.lzu.edu.cn/ubuntu precise-backports main restricted universe multiverse\r\n
\r\n
deb http://mirror.lzu.edu.cn/deepin quantal main non-free\r\n
deb-src http://mirror.lzu.edu.cn/deepin quantal main non-free\r\n
\r\n
deb http://mirror.lzu.edu.cn/deepin quantal-updates main non-free\r\n
deb-src http://mirror.lzu.edu.cn/deepin quantal-updates main non-free\r\n
</string>
<string name="fedora">#Welcome to LZUOSS Mirror Website\r\n
#\r\n
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:\r\n
#Email:oss.lzu.edu.cn@gmail.com\r\n
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)\r\n
#QQ Group:247736999\r\n
#\r\n
#Our Website:http://oss.lzu.edu.cn\r\n
#Our Mirror:http://mirror.lzu.edu.cn\r\n
#Our Project Center(GIT):http://oss.lzu.edu.cn/project\r\n
#Our Blog:http://oss.lzu.edu.cn/blog\r\n
#\r\n
#\r\n
#\r\n
#Back up your files before any change\r\n
#\r\n
#Create a new file "fedora-LZUOSS.repo"(without quotation marks) with content below:\r\n
############START_FEDORA_LZUOSS.REPO\r\n
[fedora]\r\n
name=Fedora $releasever - $basearch - LZUOSS\r\n
failovermethod=priority\r\n
baseurl=http://mirror.lzu.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/\r\n
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch\r\n
enabled=1\r\n
metadata_expire=7d\r\n
gpgcheck=1\r\n
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch\r\n
\r\n
[fedora-debuginfo]\r\n
name=Fedora $releasever - $basearch - Debug - LZUOSS\r\n
failovermethod=priority\r\n
baseurl=http://mirror.lzu.edu.cn/fedora/releases/$releasever/Everything/$basearch/debug/\r\n
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-debug-$releasever&arch=$basearch\r\n
enabled=0\r\n
metadata_expire=7d\r\n
gpgcheck=1\r\n
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch\r\n
\r\n
[fedora-source]\r\n
name=Fedora $releasever - Source - LZUOSS\r\n
failovermethod=priority\r\n
baseurl=http://mirror.lzu.edu.cn/fedora/releases/$releasever/Everything/source/SRPMS/\r\n
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-source-$releasever&arch=$basearch\r\n
enabled=0\r\n
metadata_expire=7d\r\n
gpgcheck=1\r\n
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch\r\n
############END_FEDORA_LZUOSS.REPO\r\n
#And put this file in /etc/yum.repos.d/\r\n
#\r\n
#Create a new file "fedora-updates-LZUOSS.repo"(without quotation marks) with content below:\r\n
############START_FEDORA_UPDATES_LZUOSS.REPO\r\n
[updates]\r\n
name=Fedora $releasever - $basearch - Updates - LZUOSS\r\n
failovermethod=priority\r\n
baseurl=http://mirror.lzu.edu.cn/fedora/updates/$releasever/$basearch/\r\n
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch\r\n
enabled=1\r\n
gpgcheck=1\r\n
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch\r\n
\r\n
[updates-debuginfo]\r\n
name=Fedora $releasever - $basearch - Updates - Debug - LZUOSS\r\n
failovermethod=priority\r\n
baseurl=http://mirror.lzu.edu.cn/fedora/updates/$releasever/$basearch/debug/\r\n
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f$releasever&arch=$basearch\r\n
enabled=0\r\n
gpgcheck=1\r\n
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch\r\n
\r\n
[updates-source]\r\n
name=Fedora $releasever - Updates Source - LZUOSS\r\n
failovermethod=priority\r\n
baseurl=http://mirror.lzu.edu.cn/fedora/updates/$releasever/SRPMS/\r\n
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f$releasever&arch=$basearch\r\n
enabled=0\r\n
gpgcheck=1\r\n
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch\r\n
############END_FEDORA_UPDATES_LZUOSS.REPO\r\n
#And put this file in /etc/yum.repos.d/\r\n
#\r\n
#Make cahce use command like this: yum makecache\r\n
</string>
<string name="gentoo">#Welcome to LZUOSS Mirror Website\r\n
#\r\n
##This mirror is maintained by LZUOSS, if you have any problem, please let us know in several approaches:\r\n
#Email:oss.lzu.edu.cn@gmail.com\r\n
#Google Public Group:come-on-all@googlegroups.com(https://groups.google.com/d/forum/come-on-all?hl=zh-CN)\r\n
#QQ Group:247736999\r\n
#\r\n
#Our Website:http://oss.lzu.edu.cn\r\n
#Our Mirror:http://mirror.lzu.edu.cn\r\n
#Our Project Center(GIT):http://oss.lzu.edu.cn/project\r\n
#Our Blog:http://oss.lzu.edu.cn/blog\r\n
#\r\n
#\r\n
#\r\n
#Back up your files before any change\r\n
#\r\n
#\r\n
#Add or update the file in /etc/make.conf with the last line\r\n
\r\n
GENTOO_MIRRORS="http://mirror.lzu.edu.cn/gentoo/"   \r\n
</string>
<string name="opensuse"></string>
<string name="users">
ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3\r\n

ftpserver.user.admin.homedirectory=/mnt/sdcard/\r\n

ftpserver.user.admin.enableflag=true\r\n

ftpserver.user.admin.writepermission=true\r\n

ftpserver.user.admin.maxloginnumber=0\r\n

ftpserver.user.admin.maxloginperip=0\r\n

ftpserver.user.admin.idletime=0\r\n

ftpserver.user.admin.uploadrate=0\r\n

ftpserver.user.admin.downloadrate=0\r\n


ftpserver.user.anonymous.userpassword=\r\n

ftpserver.user.anonymous.homedirectory=/mnt/sdcard/\r\n

ftpserver.user.anonymous.enableflag=true\r\n

ftpserver.user.anonymous.writepermission=false\r\n

ftpserver.user.anonymous.maxloginnumber=20\r\n

ftpserver.user.anonymous.maxloginperip=2\r\n

ftpserver.user.anonymous.idletime=300\r\n

ftpserver.user.anonymous.uploadrate=4800\r\n

ftpserver.user.anonymous.downloadrate=4800\r\n

</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.6\common\lib文件夹中添加需要的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<Authority> authorities = new ArrayList<Authority>();
  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加密的。其他配置项也很好理解。
2019-07-15 21:18:15 weixin_28743727 阅读数 31

这两天用了3年的mac电脑拿去检修了,自能用公司的电脑,所以需要重新搭建android开发环境。

搞个vpn能访问google

访问google下载chrome

访问android官网下载android studio

下载安装git https://git-scm.com/download

使用gitlab搭建git服务器

 

使用git bash创建公钥私钥

 

ssh-keygen -t rsa -C "your_email"

 

我的电脑已经创建了如下,创建过程中需要输入密码,这个密码要记住,待会android studio用git克隆代码时需要输入

 

用记事本打开公钥文件,全选复制一下

 

登陆gitlab服务器,进入ssh选项粘贴一下

回到android studio

输入git链接点击test或clone

会弹出要输入刚刚的git bash创建的私钥密码。密码正确即可成功!

2012-06-30 09:56:30 pzhtpf 阅读数 161488

我们平常学习时经常会写一下javaweb程序,我们为了更能逼近现实,就想着自己的javaweb程序发布后,外网的同学能够访问我们的网站,难道我们去买空间,去买域名嘛,其实也没必要,我们只是学习,测试之用,在自己的电脑上搭建一个服务器完全可以满足要求。上次写的一篇博客,PC服务端与Android客户端实现网络通信,就是利用这个原理。

我们分为三步走来实现:(我这里用的示例javaweb程序是我自己简单写的一个小程序shop1)

1

我们用Tomcat服务器,如果我们的javaweb程序已经部署到了Tomcat服务器,一般我们在本地访问的地址为:localhost:8080/shop1localhost指本机,即127.0.0.18080端口号,shop1你部署的项目名称,但太过繁琐,我们只想通过IP地址来访问我们的项目,即127.0.0.1或者localhost,我们只需修改一下Tomcat的配置即可,打开Tomcat所在的目录,打开conf文件夹,打开server.xml文件,所要修改的部分如下:

 

<Connector port="80" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

 

<Context path="" docBase="shop1" reloadable="true" />


 

即将port从原先的8080修改成80,因为http协议的默认端口是80,这样你就可以不用再输端口号了,把docBase="shop1"的值修改成你所部属的项目的名称,默认指向你的项目,这样你就可以不输项目的名称了。

还得注意一点Tomcat 7.0的版本的server.xml文件中居然没有

<Context path="" docBase="shop1" reloadable="true" />


这一条,又下载了一个5.0版本的居然有,如果你的没有,复制加进去就可以了。

OK,这样的话,你在浏览器里输入localhost就可以访问你的项目了!

PS:为了下来的工作中不出现什么问题,我并没有将8080端口改成80,据说80端口被电信封掉了,我让用电信上网的同学访问我的网站,果然不行,这里我们明白道理就可以了,只是学习测试之用,所以我们就用8080端口。

 

2

上一步我们只实现了自己访问,但如何让外网的同学访问,这里可能涉及了简单的网络知识,我网络学的也不是很好。就说的比较通俗一点。有两种情况(1)你上网没有用路由,运营商单独分给你一个IP地址,那你直接可以用你的IP让外网的同学来访问你的网站,我们这里用的是8080端口,所以形式为:XX.XX.XX.XX:8080。为了让多的同学了解,我在啰嗦一下,怎么知道自己的IP地址,你不必用在cmd命令行输入ipconfig这种略显专业的方法去获取,其实只要在百度搜索“IP查询”,第一个就是。

2)用了路由器,一个路由器带了好几台电脑,比如说跟室友,这就需要你去路由管理页面去设置一下,端口映射,让别人访问你们的IP地址时,映射到你的电脑,在浏览器中输入192.168.1.1(以你的路由为准),进入路由管理页面,操作如下图:

转发规则-----虚拟服务器-------添加新条目

端口我们没改,所以填8080IP地址为你的电脑在局域网中的地址,怎么样知道自己的局域网中的地址,很简单自己百度一下,只要局域网里的电脑不是太多,一般为192.168.1.XXX,我这里为192.168.1.101,然后点击保存,OK,然后外网就可以用你们IP去访问你的网站了!

我的效果图如下:

这时可以把这个网址发给你的同学,试一下,他能不能访问你的网站,答案是肯定的!

 

3,

但是又有新问题了,你第二天打开路由,或者再次上网时,运营商会重新分配给你一个新的IP地址,难道你让你同学访问时,再次把这个IP地址发给他吗?显然这是不合理了。

此时,我们就想有一个动态域名多好。这里给大家介绍一款软件“花生壳”,下载安装,然后注册后,你就会获得一个免费的二级域名,每次开机自启后,就会将花生壳服务端中的IP数据更新成你新的IP地址,然后你每次用你固定的域名来访问时,就会解析到你新的IP地址。

如下图:

双击你的域名,看有没有显示出“经检测,您的域名已激活并指向正确”!

 

OK,到这里,没有路由的同学,就可以直接用你的域名访问了!

 

有路由的同学,还得多操作一步:

再次进入路由管理页面,操作如下图:

点击“动态DNS,这时如果你的上述操作都没问题的话,服务提供者那一栏已经自动填充成花生壳的网址了,然后输入用户名,密码,点击登录,如果显示为“连接成功”,那点击“保存”。

到这里,终于大功告成,看一下最终效果图:

可以看到,我用我的域名成功的访问到了我的网站。

PS:有时显示“验证成功”时也是个假象,一点击“保存”时,又显示为“验证失败”,再点击“登录”,多点击几次“保存”,直到它一直显示为“验证成功”即可,反正就是多试几次。

祝君好运!

2017-04-29 10:48:55 gucheng3116 阅读数 8612

  在学习Android开发网络知识的部分,为了便于调试,需要自己搭建服务器。没有必要从网络上花钱购买服务器,这里我们可以自己在电脑上搭建本地服务器。只要电脑和手机连接到了同一个局域网,比如都连接同一个家里的路由器。就可以通过手机来访问本地服务器了。使用wamp可以非常快速方便地搭建服务器,wamp集成了Apache服务器而且安装起来非常地简单方便。WAMP是Windows环境下的Apache服务器,Mysql,Php的集合。本文就介绍如何使用wamp搭建服务器以及通过手机来访问。

  • 1 下载wamp软件安装包

  官网地址是:http://www.wampserver.com/,在官网上有32位和64位可供选择,根据自己的系统类型选择需要的版本。
这里写图片描述

  这里我选择32位的版本,点击32位的按钮后会弹出一个填写基本信息的对话框,不用管它,直接点击下图方框中的链接即可下载一个后缀名为exe的安装包。
这里写图片描述

  • 2 安装wamp

  双击安装包即可开始安装。安装过程中只支持英语和法语,不过在程序运行起来之后可以修改。
这里写图片描述

  安装过程中需要选择安装路径,这里的安装路径包含了存放网页的目录。总目录名为wamp,存放网页的子目录名为www。默认在C盘根目录,这里我将其改为E盘根目录。
这里写图片描述

  安装过程中会让我们选择默认的浏览器,默认为IE,也可以改成其他我们常用的浏览器。
这里写图片描述

  同样的,也会让你选择默认的编辑器。
  安装完成后,提示界面如下图。
这里写图片描述

  双击快捷方式或在开始中启动程序。在右下角的任务栏中会多出一个W小图标。如果正常启动的话,W小图标会从红色变成绿色。红色表示停止服务,绿色表示正在服务。
这里写图片描述

  正常运行时将鼠标停留在W图标上会显示All Services running.
这里写图片描述

  在W图标上单机鼠标左键,弹出菜单中选择Localhost,即可打开浏览器,进入到欢迎页面。
这里写图片描述

这里写图片描述

  如果正常显示欢迎页面,说明在电脑上我们已经正常搭建了服务器。接下来我们来看一下怎么通过手机访问。

  • 3 用手机访问服务器

  用手机访问电脑上的服务器,首先我们应该要和电脑在同一个局域网。这里我的笔记本和手机连接到的都是同一个路由器。接下来,用手机访问电脑,我们需要知道电脑的IP地址。开始中输入cmd,在cmd程序上单机右键,选择以管理员身份运行。输入命令ipconfig,得到如下信息:
这里写图片描述

  这里我们能看到两处IP地址,我们要选择的是无线局域网适配器下面的IP地址,也就是192.168.1.4。

  打开手机浏览器,输入该地址。输入该地址后,我的手机上打开的网页如下,提示
  You don’t have permission to access/on this server.
这里写图片描述

  出现这样的提示,说明我们手机已经连接到电脑上的服务器了,只是被服务器拒绝访问。这里我们只需要简单配置一下就行。单击左键,在弹出菜单的Apache目录的子目录中选择httpd-vhost.conf。
将图中的Require local改为Require all granted。
这里写图片描述

  重启wamp软件,在手机上刷新一下页面即可正常显示出欢迎页面。
这里写图片描述

  这样,我们就使用wamp正确地搭建了本地服务器,并可以通过手机来访问。接下来,就可以继续学习Android网络相关的知识了。

  如果你在安装过程中还存在其它什么问题,可以在评论区提问或者给我发邮件459849997@qq.com 。

没有更多推荐了,返回首页