View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.net.ftp;
19  
20  /***
21   * FTPReply stores a set of constants for FTP reply codes.  To interpret
22   * the meaning of the codes, familiarity with RFC 959 is assumed.
23   * The mnemonic constant names are transcriptions from the code descriptions
24   * of RFC 959.  For those who think in terms of the actual reply code values,
25   * a set of CODE_NUM constants are provided where NUM is the numerical value
26   * of the code.
27   * <p>
28   * <p>
29   * @author Daniel F. Savarese
30   ***/
31  
32  public final class FTPReply
33  {
34  
35      public static final int CODE_110 = 110;
36      public static final int CODE_120 = 120;
37      public static final int CODE_125 = 125;
38      public static final int CODE_150 = 150;
39      public static final int CODE_200 = 200;
40      public static final int CODE_202 = 202;
41      public static final int CODE_211 = 211;
42      public static final int CODE_212 = 212;
43      public static final int CODE_213 = 213;
44      public static final int CODE_214 = 214;
45      public static final int CODE_215 = 215;
46      public static final int CODE_220 = 220;
47      public static final int CODE_221 = 221;
48      public static final int CODE_225 = 225;
49      public static final int CODE_226 = 226;
50      public static final int CODE_227 = 227;
51      public static final int CODE_230 = 230;
52      public static final int CODE_250 = 250;
53      public static final int CODE_257 = 257;
54      public static final int CODE_331 = 331;
55      public static final int CODE_332 = 332;
56      public static final int CODE_350 = 350;
57      public static final int CODE_421 = 421;
58      public static final int CODE_425 = 425;
59      public static final int CODE_426 = 426;
60      public static final int CODE_450 = 450;
61      public static final int CODE_451 = 451;
62      public static final int CODE_452 = 452;
63      public static final int CODE_500 = 500;
64      public static final int CODE_501 = 501;
65      public static final int CODE_502 = 502;
66      public static final int CODE_503 = 503;
67      public static final int CODE_504 = 504;
68      public static final int CODE_521 = 521;
69      public static final int CODE_530 = 530;
70      public static final int CODE_532 = 532;
71      public static final int CODE_550 = 550;
72      public static final int CODE_551 = 551;
73      public static final int CODE_552 = 552;
74      public static final int CODE_553 = 553;
75  
76      public static final int RESTART_MARKER = CODE_110;
77      public static final int SERVICE_NOT_READY = CODE_120;
78      public static final int DATA_CONNECTION_ALREADY_OPEN = CODE_125;
79      public static final int FILE_STATUS_OK = CODE_150;
80      public static final int COMMAND_OK = CODE_200;
81      public static final int COMMAND_IS_SUPERFLUOUS = CODE_202;
82      public static final int SYSTEM_STATUS = CODE_211;
83      public static final int DIRECTORY_STATUS = CODE_212;
84      public static final int FILE_STATUS = CODE_213;
85      public static final int HELP_MESSAGE = CODE_214;
86      public static final int NAME_SYSTEM_TYPE = CODE_215;
87      public static final int SERVICE_READY = CODE_220;
88      public static final int SERVICE_CLOSING_CONTROL_CONNECTION = CODE_221;
89      public static final int DATA_CONNECTION_OPEN = CODE_225;
90      public static final int CLOSING_DATA_CONNECTION = CODE_226;
91      public static final int ENTERING_PASSIVE_MODE = CODE_227;
92      public static final int USER_LOGGED_IN = CODE_230;
93      public static final int FILE_ACTION_OK = CODE_250;
94      public static final int PATHNAME_CREATED = CODE_257;
95      public static final int NEED_PASSWORD = CODE_331;
96      public static final int NEED_ACCOUNT = CODE_332;
97      public static final int FILE_ACTION_PENDING = CODE_350;
98      public static final int SERVICE_NOT_AVAILABLE = CODE_421;
99      public static final int CANNOT_OPEN_DATA_CONNECTION = CODE_425;
100     public static final int TRANSFER_ABORTED = CODE_426;
101     public static final int FILE_ACTION_NOT_TAKEN = CODE_450;
102     public static final int ACTION_ABORTED = CODE_451;
103     public static final int INSUFFICIENT_STORAGE = CODE_452;
104     public static final int UNRECOGNIZED_COMMAND = CODE_500;
105     public static final int SYNTAX_ERROR_IN_ARGUMENTS = CODE_501;
106     public static final int COMMAND_NOT_IMPLEMENTED = CODE_502;
107     public static final int BAD_COMMAND_SEQUENCE = CODE_503;
108     public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = CODE_504;
109     public static final int NOT_LOGGED_IN = CODE_530;
110     public static final int NEED_ACCOUNT_FOR_STORING_FILES = CODE_532;
111     public static final int FILE_UNAVAILABLE = CODE_550;
112     public static final int PAGE_TYPE_UNKNOWN = CODE_551;
113     public static final int STORAGE_ALLOCATION_EXCEEDED = CODE_552;
114     public static final int FILE_NAME_NOT_ALLOWED = CODE_553;
115     
116     // FTPS Reply Codes
117     /** @since 2.0 */
118     public static final int CODE_234 = 234;
119     /** @since 2.0 */
120     public static final int CODE_235 = 235;
121     /** @since 2.0 */
122     public static final int CODE_334 = 334;
123     /** @since 2.0 */
124     public static final int CODE_335 = 335;
125     /** @since 2.0 */
126     public static final int CODE_431 = 431;
127     /** @since 2.0 */
128     public static final int CODE_533 = 533;
129     /** @since 2.0 */
130     public static final int CODE_534 = 534;
131     /** @since 2.0 */
132     public static final int CODE_535 = 535;
133     /** @since 2.0 */
134     public static final int CODE_536 = 536;
135     
136     /** @since 2.0 */
137     public static final int SECURITY_DATA_EXCHANGE_COMPLETE = CODE_234;
138     /** @since 2.0 */
139     public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = CODE_235;
140     /** @since 2.0 */
141     public static final int SECURITY_MECHANISM_IS_OK = CODE_334;
142     /** @since 2.0 */
143     public static final int SECURITY_DATA_IS_ACCEPTABLE = CODE_335;
144     /** @since 2.0 */
145     public static final int UNAVAILABLE_RESOURCE = CODE_431;
146     /** @since 2.0 */
147     public static final int DENIED_FOR_POLICY_REASONS = CODE_533;
148     /** @since 2.0 */
149     public static final int REQUEST_DENIED = CODE_534;
150     /** @since 2.0 */
151     public static final int FAILED_SECURITY_CHECK = CODE_535;
152     /** @since 2.0 */
153     public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = CODE_536;
154     
155 
156     // Cannot be instantiated
157     private FTPReply()
158     {}
159 
160     /***
161      * Determine if a reply code is a positive preliminary response.  All
162      * codes beginning with a 1 are positive preliminary responses.
163      * Postitive preliminary responses are used to indicate tentative success.
164      * No further commands can be issued to the FTP server after a positive
165      * preliminary response until a follow up response is received from the
166      * server.
167      * <p>
168      * @param reply  The reply code to test.
169      * @return True if a reply code is a postive preliminary response, false
170      *         if not.
171      ***/
172     public static boolean isPositivePreliminary(int reply)
173     {
174         return (reply >= 100 && reply < 200);
175     }
176 
177     /***
178      * Determine if a reply code is a positive completion response.  All
179      * codes beginning with a 2 are positive completion responses.
180      * The FTP server will send a positive completion response on the final
181      * successful completion of a command.
182      * <p>
183      * @param reply  The reply code to test.
184      * @return True if a reply code is a postive completion response, false
185      *         if not.
186      ***/
187     public static boolean isPositiveCompletion(int reply)
188     {
189         return (reply >= 200 && reply < 300);
190     }
191 
192     /***
193      * Determine if a reply code is a positive intermediate response.  All
194      * codes beginning with a 3 are positive intermediate responses.
195      * The FTP server will send a positive intermediate response on the
196      * successful completion of one part of a multi-part sequence of
197      * commands.  For example, after a successful USER command, a positive
198      * intermediate response will be sent to indicate that the server is
199      * ready for the PASS command.
200      * <p>
201      * @param reply  The reply code to test.
202      * @return True if a reply code is a postive intermediate response, false
203      *         if not.
204      ***/
205     public static boolean isPositiveIntermediate(int reply)
206     {
207         return (reply >= 300 && reply < 400);
208     }
209 
210     /***
211      * Determine if a reply code is a negative transient response.  All
212      * codes beginning with a 4 are negative transient responses.
213      * The FTP server will send a negative transient response on the
214      * failure of a command that can be reattempted with success.
215      * <p>
216      * @param reply  The reply code to test.
217      * @return True if a reply code is a negative transient response, false
218      *         if not.
219      ***/
220     public static boolean isNegativeTransient(int reply)
221     {
222         return (reply >= 400 && reply < 500);
223     }
224 
225     /***
226      * Determine if a reply code is a negative permanent response.  All
227      * codes beginning with a 5 are negative permanent responses.
228      * The FTP server will send a negative permanent response on the
229      * failure of a command that cannot be reattempted with success.
230      * <p>
231      * @param reply  The reply code to test.
232      * @return True if a reply code is a negative permanent response, false
233      *         if not.
234      ***/
235     public static boolean isNegativePermanent(int reply)
236     {
237         return (reply >= 500 && reply < 600);
238     }
239 
240 }