1 14 15 package ftpserver; 16 17 18 import java.io.*; 19 import java.net.SocketTimeoutException ; 20 import org.quickserver.net.server.*; 21 import org.quickserver.net.qsadmin.*; 22 import java.util.*; 23 import org.quickserver.util.xmlreader.ApplicationConfiguration; 24 25 public class QSAdminCommandPlugin implements CommandPlugin { 26 32 public boolean handleCommand(ClientHandler handler, String command) 33 throws SocketTimeoutException , IOException { 34 35 QuickServer ftpqs = (QuickServer) 36 handler.getServer().getStoreObjects()[0]; 37 38 if(command.toLowerCase().startsWith("set ftproot ")) { 39 String temp = ""; 40 temp = command.substring("set ftproot ".length()); 41 ApplicationConfiguration appConfig = ftpqs.getConfig().getApplicationConfiguration(); 42 File root = new File(temp); 43 if(root.canRead() && root.isDirectory()) { 44 if(appConfig==null) 45 appConfig = new ApplicationConfiguration(); 46 appConfig.put("FTP_ROOT", temp); 47 ftpqs.getConfig().setApplicationConfiguration(appConfig); 48 handler.sendClientMsg("+OK root changed"); 49 } else { 50 handler.sendClientMsg("-ERR not a directory or can't read : "+temp); 51 } 52 return true; 53 } else if(command.toLowerCase().equals("get ftproot")) { 54 HashMap appConfig = ftpqs.getConfig().getApplicationConfiguration(); 55 String temp = null; 56 if(appConfig!=null) 57 temp = (String )appConfig.get("FTP_ROOT"); 58 else 59 temp = System.getProperty("user.home"); 60 handler.sendClientMsg("+OK " + temp); 61 return true; 62 } else if(command.toLowerCase().equals("help")) { 63 handler.sendClientMsg("+OK info follows"); 64 handler.sendClientMsg("Custom Commands:"); 65 handler.sendClientMsg("\tset ftproot <path> //Sets FTP root directory"); 66 handler.sendClientMsg("\tget ftproot //Returns the current FTP root directory"); 67 handler.sendClientMsg(" "); 68 handler.sendClientMsg("Standard Commands:"); 69 handler.sendClientMsg("\tRefer Api Docs for org.quickserver.net.qsadmin.CommandHandler"); 70 handler.sendClientMsg("."); 71 return true; 72 } 73 return false; 74 } 75 } 76
| Popular Tags
|