⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server_state.java

📁 用java写的SFTP代码
💻 JAVA
字号:
/**
 *协议的服务器端准备状态.
 *是Idle状态选择的下一个状态
 *执行它的doIt方法,并转入下一个状态
 */
import java.io.*;
public class Server_State extends State {
	String dir = null;
	//这个方法提供了所要求的状态的功能,并决定下一个状态
	State doIt() {
		//选择服务器端的功能
		System.out.println("当前为服务器端 -- 简单FTP (基于TFTP协议) \n\n");
		System.out.println("请按键选择:\n");
		System.out.println("n  <继续,选择您的目录>\nr   <返回上一状态>");
		SimpleIO input = new SimpleIO(System.in);
		String choice = input.readString();
		if(choice.equals("r")) {
			this.next_state = new Idle();
			return this.next_state;
		}
		else if(choice.equals("n")) {
			File f = new File("c:\\Sftp.dir\\");//创建服务器端的目录
			if(f.exists()==false) {
				boolean iscreate = f.mkdir();
				if(iscreate==false) {
					System.out.println("不能创建目录!");
					this.next_state = new Server_State();
					return this.next_state;
				}
				else {
					System.out.println("创建目录c:\\Sftp.dir\\");
					this.next_state = new Server_Start();
					return this.next_state;
				}
			}
			else {								//如果目录存在的话
				this.next_state = new Server_Start();
				return this.next_state;
			}
			//把目录放在一个文件中
			}
		else {									//按了其他的按键
				this.next_state = new Server_State();
				return this.next_state;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -