KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ftpserver > QSAdminCommandPlugin


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package ftpserver;
16
17
18 import java.io.*;
19 import java.net.SocketTimeoutException JavaDoc;
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     /**
27      * FTP Server QSAdminServer commands
28      * ----------------------------------
29      * set ftproot path
30      * get ftptoot
31      */

32     public boolean handleCommand(ClientHandler handler, String JavaDoc command)
33         throws SocketTimeoutException JavaDoc, IOException {
34
35         QuickServer ftpqs = (QuickServer)
36             handler.getServer().getStoreObjects()[0];
37
38         if(command.toLowerCase().startsWith("set ftproot ")) {
39             String JavaDoc 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 JavaDoc temp = null;
56             if(appConfig!=null)
57                 temp = (String JavaDoc)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