01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
14:
15: package ftpserver;
16:
17: import java.io.*;
18: import java.net.SocketTimeoutException;
19: import org.quickserver.net.server.*;
20: import org.quickserver.net.qsadmin.*;
21: import java.util.*;
22: import org.quickserver.util.xmlreader.ApplicationConfiguration;
23:
24: public class QSAdminCommandPlugin implements CommandPlugin {
25: /**
26: * FTP Server QSAdminServer commands
27: * ----------------------------------
28: * set ftproot path
29: * get ftptoot
30: */
31: public boolean handleCommand(ClientHandler handler, String command)
32: throws SocketTimeoutException, IOException {
33:
34: QuickServer ftpqs = (QuickServer) handler.getServer()
35: .getStoreObjects()[0];
36:
37: if (command.toLowerCase().startsWith("set ftproot ")) {
38: String temp = "";
39: temp = command.substring("set ftproot ".length());
40: ApplicationConfiguration appConfig = ftpqs.getConfig()
41: .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()
48: .setApplicationConfiguration(appConfig);
49: handler.sendClientMsg("+OK root changed");
50: } else {
51: handler
52: .sendClientMsg("-ERR not a directory or can't read : "
53: + temp);
54: }
55: return true;
56: } else if (command.toLowerCase().equals("get ftproot")) {
57: HashMap appConfig = ftpqs.getConfig()
58: .getApplicationConfiguration();
59: String temp = null;
60: if (appConfig != null)
61: temp = (String) appConfig.get("FTP_ROOT");
62: else
63: temp = System.getProperty("user.home");
64: handler.sendClientMsg("+OK " + temp);
65: return true;
66: } else if (command.toLowerCase().equals("help")) {
67: handler.sendClientMsg("+OK info follows");
68: handler.sendClientMsg("Custom Commands:");
69: handler
70: .sendClientMsg("\tset ftproot <path> //Sets FTP root directory");
71: handler
72: .sendClientMsg("\tget ftproot //Returns the current FTP root directory");
73: handler.sendClientMsg(" ");
74: handler.sendClientMsg("Standard Commands:");
75: handler
76: .sendClientMsg("\tRefer Api Docs for org.quickserver.net.qsadmin.CommandHandler");
77: handler.sendClientMsg(".");
78: return true;
79: }
80: return false;
81: }
82: }
|