1 18 package net.sf.drftpd.master.command.plugins; 19 20 import java.io.PrintWriter ; 21 import java.util.Date ; 22 import java.util.Iterator ; 23 24 import net.sf.drftpd.master.BaseFtpConnection; 25 import net.sf.drftpd.master.FtpReply; 26 import net.sf.drftpd.master.command.CommandManager; 27 import net.sf.drftpd.master.command.CommandManagerFactory; 28 import net.sf.drftpd.slave.SlaveImpl; 29 30 import org.drftpd.commands.CommandHandler; 31 import org.drftpd.commands.CommandHandlerFactory; 32 import org.drftpd.commands.UnhandledCommandException; 33 34 37 public class Misc implements CommandHandlerFactory, CommandHandler { 38 50 private FtpReply doABOR(BaseFtpConnection conn) { 51 return FtpReply.RESPONSE_226_CLOSING_DATA_CONNECTION; 52 } 53 54 private FtpReply doFEAT(BaseFtpConnection conn) { 56 PrintWriter out = conn.getControlWriter(); 57 out.print("211-Extensions supported:\r\n"); 58 for (Iterator iter = conn.getCommandManager().getCommandHandlersMap().values().iterator(); iter.hasNext();) { 59 CommandHandler hnd = (CommandHandler) iter.next(); 60 String feat[] = hnd.getFeatReplies(); 61 if(feat == null) continue; 62 for (int i = 0; i < feat.length; i++) { 63 out.print(" "+feat[i]+"\r\n"); 64 } 65 } 66 out.print("211 End\r\n"); 72 return null; 73 } 74 75 84 116 private FtpReply doSITE_STAT(BaseFtpConnection conn) { 117 if (conn.getRequest().hasArgument()) { 118 return FtpReply.RESPONSE_504_COMMAND_NOT_IMPLEMENTED_FOR_PARM; 119 } 120 FtpReply response = (FtpReply) FtpReply.RESPONSE_200_COMMAND_OK.clone(); 121 122 response.addComment(conn.status()); 123 return response; 124 } 125 126 private FtpReply doSITE_TIME(BaseFtpConnection conn) { 127 if (conn.getRequest().hasArgument()) { 128 return FtpReply.RESPONSE_501_SYNTAX_ERROR; 129 } 130 return new FtpReply(200, "Server time is: " + new Date ()); 131 } 132 133 private FtpReply doSITE_VERS(BaseFtpConnection conn) { 134 return new FtpReply(200, SlaveImpl.VERSION); 135 } 136 137 public FtpReply execute(BaseFtpConnection conn) throws UnhandledCommandException { 138 String cmd = conn.getRequest().getCommand(); 139 if("ABOR".equals(cmd)) return doABOR(conn); 140 if("FEAT".equals(cmd)) return doFEAT(conn); 141 if("SITE STAT".equals(cmd)) return doSITE_STAT(conn); 142 if("SITE TIME".equals(cmd)) return doSITE_TIME(conn); 143 if("SITE VERS".equals(cmd)) return doSITE_VERS(conn); 144 throw UnhandledCommandException.create(Misc.class, conn.getRequest()); 145 } 146 147 public CommandHandler initialize(BaseFtpConnection conn, CommandManager initializer) { 148 return this; 149 } 150 151 public String [] getFeatReplies() { 152 return null; 153 } 154 155 public void load(CommandManagerFactory initializer) {} 156 public void unload() {} 157 158 } 159 | Popular Tags |