1 18 package net.sf.drftpd.master; 19 20 import java.io.BufferedReader ; 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 import java.util.Vector ; 24 25 import org.apache.log4j.Level; 26 import org.apache.log4j.Logger; 27 28 32 public class FtpReply implements Cloneable { 33 private static final Logger logger = 34 Logger.getLogger(FtpReply.class.getName()); 35 36 37 public static final String RESPONSE_150_OK = 38 "150 File status okay; about to open data connection.\r\n"; 39 40 41 public static final FtpReply RESPONSE_200_COMMAND_OK = 42 new FtpReply(200, "Command okay"); 43 44 45 public static final FtpReply RESPONSE_202_COMMAND_NOT_IMPLEMENTED = 46 new FtpReply( 47 202, 48 "Command not implemented, superfluous at this site."); 49 50 51 public static final FtpReply RESPONSE_215_SYSTEM_TYPE = 52 new FtpReply(215, "UNIX system type."); 53 54 55 public static final FtpReply RESPONSE_221_SERVICE_CLOSING = 56 new FtpReply(221, "Service closing control connection."); 57 58 59 public static final FtpReply RESPONSE_226_CLOSING_DATA_CONNECTION = 60 new FtpReply(226, "Closing data connection"); 61 62 63 public static final FtpReply RESPONSE_230_USER_LOGGED_IN = 64 new FtpReply(230, "User logged in, proceed."); 65 66 67 public static final FtpReply RESPONSE_250_ACTION_OKAY = 68 new FtpReply(250, "Requested file action okay, completed."); 69 70 71 public static final FtpReply RESPONSE_331_USERNAME_OK_NEED_PASS = 72 new FtpReply(331, "User name okay, need password."); 73 74 75 public static final FtpReply RESPONSE_350_PENDING_FURTHER_INFORMATION = 76 new FtpReply( 77 350, 78 "Requested file action pending further information."); 79 80 81 public static final String RESPONSE_425_CANT_OPEN_DATA_CONNECTION = 82 "425 Can't open data connection.\r\n"; 83 84 85 public static final FtpReply RESPONSE_426_CONNECTION_CLOSED_TRANSFER_ABORTED = 86 new FtpReply(426, "Connection closed; transfer aborted."); 87 88 89 public static final FtpReply RESPONSE_450_REQUESTED_ACTION_NOT_TAKEN = 90 new FtpReply(450, "Requested file action not taken."); 91 92 95 public static final FtpReply RESPONSE_450_SLAVE_UNAVAILABLE = 96 new FtpReply(450, "No transfer-slave(s) available"); 97 98 99 public static final FtpReply RESPONSE_500_SYNTAX_ERROR = 100 new FtpReply(500, "Syntax error, command unrecognized."); 101 102 103 public static final FtpReply RESPONSE_501_SYNTAX_ERROR = 104 new FtpReply(501, "Syntax error in parameters or arguments"); 105 106 107 public static final FtpReply RESPONSE_502_COMMAND_NOT_IMPLEMENTED = 108 new FtpReply(502, "Command not implemented."); 109 110 111 public static final FtpReply RESPONSE_503_BAD_SEQUENCE_OF_COMMANDS = 112 new FtpReply(503, "Bad sequence of commands."); 113 114 115 public static final FtpReply RESPONSE_504_COMMAND_NOT_IMPLEMENTED_FOR_PARM = 116 new FtpReply(504, "Command not implemented for that parameter."); 117 118 119 public static final FtpReply RESPONSE_530_ACCESS_DENIED = 120 new FtpReply(530, "Access denied"); 121 122 123 public static final FtpReply RESPONSE_530_NOT_LOGGED_IN = 124 new FtpReply(530, "Not logged in."); 125 126 public static final FtpReply RESPONSE_530_SLAVE_UNAVAILABLE = 127 new FtpReply(530, "No transfer-slave(s) available"); 128 129 132 public static final FtpReply RESPONSE_550_REQUESTED_ACTION_NOT_TAKEN = 133 new FtpReply(550, "Requested action not taken. File unavailable."); 134 135 138 public static final FtpReply RESPONSE_553_REQUESTED_ACTION_NOT_TAKEN = 139 new FtpReply(553, "Requested action not taken."); 140 protected int _code; 141 142 protected Vector _lines = new Vector (); 143 protected String _message; 144 145 public FtpReply() { 146 } 147 public FtpReply(int code) { 148 setCode(code); 149 } 150 public FtpReply(int code, String response) { 151 setCode(code); 152 setMessage(response); 153 } 154 155 public FtpReply addComment(BufferedReader in) throws IOException { 156 String line; 157 while ((line = in.readLine()) != null) { this.addComment(line); 159 } 160 return this; 161 } 162 163 public FtpReply addComment(Object response) { 164 _lines.add(String.valueOf(response)); 165 return this; 166 } 167 168 public Object clone() { 169 try { 170 FtpReply r = (FtpReply) super.clone(); 171 r._lines = (Vector ) _lines.clone(); 172 return r; 173 } catch (CloneNotSupportedException ex) { 174 throw new RuntimeException (ex); 175 } 176 } 177 178 public int getCode() { 179 return _code; 180 } 181 public void setCode(int code) { 182 _code = code; 183 } 184 public void setMessage(String response) { 185 int pos = response.indexOf('\n'); 186 if (pos != -1) { 187 addComment(response.substring(pos+1)); 188 response = response.substring(0, pos); 189 logger.log(Level.DEBUG, "Truncated response message with multiple lines: "+response); 190 } 191 _message = response; 192 } 193 public int size() { 194 return _lines.size(); 195 } 196 197 public String toString() { 198 StringBuffer sb = new StringBuffer (); 199 if(_lines.size() == 0 && _message == null) setMessage("No text specified"); 201 for (Iterator iter = _lines.iterator(); iter.hasNext();) { 202 String comment = (String ) iter.next(); 203 if (!iter.hasNext() && _message == null) { 204 sb.append(_code + " " + comment + "\r\n"); 205 } else { 206 sb.append(_code + "- " + comment + "\r\n"); 207 } 208 } 209 if (_message != null) 210 sb.append(_code + " " + _message + "\r\n"); 211 return sb.toString(); 212 } 213 214 } 215 | Popular Tags |