KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > FtpReply


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import org.apache.log4j.Level;
26 import org.apache.log4j.Logger;
27
28 /**
29  * @author mog
30  * @version $Id: FtpReply.java,v 1.11 2004/05/10 02:53:59 mog Exp $
31  */

32 public class FtpReply implements Cloneable JavaDoc {
33     private static final Logger logger =
34         Logger.getLogger(FtpReply.class.getName());
35
36     /** 150 File status okay; about to open data connection. */
37     public static final String JavaDoc RESPONSE_150_OK =
38         "150 File status okay; about to open data connection.\r\n";
39
40     /** 200 Command okay */
41     public static final FtpReply RESPONSE_200_COMMAND_OK =
42         new FtpReply(200, "Command okay");
43
44     /** 202 Command not implemented, superfluous at this site. */
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     /** 215 NAME system type. */
51     public static final FtpReply RESPONSE_215_SYSTEM_TYPE =
52         new FtpReply(215, "UNIX system type.");
53
54     /** 221 Service closing control connection. */
55     public static final FtpReply RESPONSE_221_SERVICE_CLOSING =
56         new FtpReply(221, "Service closing control connection.");
57
58     /** 226 Closing data connection */
59     public static final FtpReply RESPONSE_226_CLOSING_DATA_CONNECTION =
60         new FtpReply(226, "Closing data connection");
61
62     /** 230 User logged in, proceed. */
63     public static final FtpReply RESPONSE_230_USER_LOGGED_IN =
64         new FtpReply(230, "User logged in, proceed.");
65
66     /** 250 Requested file action okay, completed. */
67     public static final FtpReply RESPONSE_250_ACTION_OKAY =
68         new FtpReply(250, "Requested file action okay, completed.");
69
70     /** 331 User name okay, need password. */
71     public static final FtpReply RESPONSE_331_USERNAME_OK_NEED_PASS =
72         new FtpReply(331, "User name okay, need password.");
73
74     /** 350 Requested file action pending further information. */
75     public static final FtpReply RESPONSE_350_PENDING_FURTHER_INFORMATION =
76         new FtpReply(
77             350,
78             "Requested file action pending further information.");
79
80     /** 425 Can't open data connection. */
81     public static final String JavaDoc RESPONSE_425_CANT_OPEN_DATA_CONNECTION =
82         "425 Can't open data connection.\r\n";
83     
84     /** 426 Connection closed; transfer aborted. */
85     public static final FtpReply RESPONSE_426_CONNECTION_CLOSED_TRANSFER_ABORTED =
86         new FtpReply(426, "Connection closed; transfer aborted.");
87         
88     /** 450 Requested file action not taken. */
89     public static final FtpReply RESPONSE_450_REQUESTED_ACTION_NOT_TAKEN =
90         new FtpReply(450, "Requested file action not taken.");
91
92     /** 450 No transfer-slave(s) available
93      * author <a HREF="mailto:drftpd@mog.se">Morgan Christiansson</a>
94      */

95     public static final FtpReply RESPONSE_450_SLAVE_UNAVAILABLE =
96         new FtpReply(450, "No transfer-slave(s) available");
97
98     /** 500 Syntax error, command unrecognized. */
99     public static final FtpReply RESPONSE_500_SYNTAX_ERROR =
100         new FtpReply(500, "Syntax error, command unrecognized.");
101
102     /** 501 Syntax error in parameters or arguments */
103     public static final FtpReply RESPONSE_501_SYNTAX_ERROR =
104         new FtpReply(501, "Syntax error in parameters or arguments");
105
106     /** 502 Command not implemented. */
107     public static final FtpReply RESPONSE_502_COMMAND_NOT_IMPLEMENTED =
108         new FtpReply(502, "Command not implemented.");
109
110     /** 503 Bad sequence of commands. */
111     public static final FtpReply RESPONSE_503_BAD_SEQUENCE_OF_COMMANDS =
112         new FtpReply(503, "Bad sequence of commands.");
113
114     /** 504 Command not implemented for that parameter. */
115     public static final FtpReply RESPONSE_504_COMMAND_NOT_IMPLEMENTED_FOR_PARM =
116         new FtpReply(504, "Command not implemented for that parameter.");
117
118     /** 530 Access denied */
119     public static final FtpReply RESPONSE_530_ACCESS_DENIED =
120         new FtpReply(530, "Access denied");
121
122     /** 530 Not logged in. */
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     /** 550 Requested action not taken. File unavailable.
130      * File unavailable (e.g., file not found, no access).
131      */

132     public static final FtpReply RESPONSE_550_REQUESTED_ACTION_NOT_TAKEN =
133         new FtpReply(550, "Requested action not taken. File unavailable.");
134
135     /** 553 Requested action not taken.
136      * File name not allowed.
137      */

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 JavaDoc _lines = new Vector JavaDoc();
143     protected String JavaDoc _message;
144
145     public FtpReply() {
146     }
147     public FtpReply(int code) {
148         setCode(code);
149     }
150     public FtpReply(int code, String JavaDoc response) {
151         setCode(code);
152         setMessage(response);
153     }
154
155     public FtpReply addComment(BufferedReader JavaDoc in) throws IOException JavaDoc {
156         String JavaDoc line;
157         while ((line = in.readLine()) != null) { //throws IOException
158
this.addComment(line);
159         }
160         return this;
161     }
162
163     public FtpReply addComment(Object JavaDoc response) {
164         _lines.add(String.valueOf(response));
165         return this;
166     }
167
168     public Object JavaDoc clone() {
169         try {
170             FtpReply r = (FtpReply) super.clone();
171             r._lines = (Vector JavaDoc) _lines.clone();
172             return r;
173         } catch (CloneNotSupportedException JavaDoc ex) {
174             throw new RuntimeException JavaDoc(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 JavaDoc 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 JavaDoc toString() {
198         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
199         //sb.append(code + "-");
200
if(_lines.size() == 0 && _message == null) setMessage("No text specified");
201         for (Iterator JavaDoc iter = _lines.iterator(); iter.hasNext();) {
202             String JavaDoc comment = (String JavaDoc) 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