001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.net.ftp;
019    
020    /***
021     * FTPReply stores a set of constants for FTP reply codes.  To interpret
022     * the meaning of the codes, familiarity with RFC 959 is assumed.
023     * The mnemonic constant names are transcriptions from the code descriptions
024     * of RFC 959.  For those who think in terms of the actual reply code values,
025     * a set of CODE_NUM constants are provided where NUM is the numerical value
026     * of the code.
027     * <p>
028     * <p>
029     * @author Daniel F. Savarese
030     * TODO replace with an enum
031     ***/
032    
033    public final class FTPReply
034    {
035    
036        public static final int CODE_110 = 110;
037        public static final int CODE_120 = 120;
038        public static final int CODE_125 = 125;
039        public static final int CODE_150 = 150;
040        public static final int CODE_200 = 200;
041        public static final int CODE_202 = 202;
042        public static final int CODE_211 = 211;
043        public static final int CODE_212 = 212;
044        public static final int CODE_213 = 213;
045        public static final int CODE_214 = 214;
046        public static final int CODE_215 = 215;
047        public static final int CODE_220 = 220;
048        public static final int CODE_221 = 221;
049        public static final int CODE_225 = 225;
050        public static final int CODE_226 = 226;
051        public static final int CODE_227 = 227;
052        /** @since 2.2 */
053        public static final int CODE_229 = 229;
054        public static final int CODE_230 = 230;
055        public static final int CODE_250 = 250;
056        public static final int CODE_257 = 257;
057        public static final int CODE_331 = 331;
058        public static final int CODE_332 = 332;
059        public static final int CODE_350 = 350;
060        public static final int CODE_421 = 421;
061        public static final int CODE_425 = 425;
062        public static final int CODE_426 = 426;
063        public static final int CODE_450 = 450;
064        public static final int CODE_451 = 451;
065        public static final int CODE_452 = 452;
066        public static final int CODE_500 = 500;
067        public static final int CODE_501 = 501;
068        public static final int CODE_502 = 502;
069        public static final int CODE_503 = 503;
070        public static final int CODE_504 = 504;
071        public static final int CODE_521 = 521;
072        public static final int CODE_530 = 530;
073        public static final int CODE_532 = 532;
074        public static final int CODE_550 = 550;
075        public static final int CODE_551 = 551;
076        public static final int CODE_552 = 552;
077        public static final int CODE_553 = 553;
078    
079        public static final int RESTART_MARKER = CODE_110;
080        public static final int SERVICE_NOT_READY = CODE_120;
081        public static final int DATA_CONNECTION_ALREADY_OPEN = CODE_125;
082        public static final int FILE_STATUS_OK = CODE_150;
083        public static final int COMMAND_OK = CODE_200;
084        public static final int COMMAND_IS_SUPERFLUOUS = CODE_202;
085        public static final int SYSTEM_STATUS = CODE_211;
086        public static final int DIRECTORY_STATUS = CODE_212;
087        public static final int FILE_STATUS = CODE_213;
088        public static final int HELP_MESSAGE = CODE_214;
089        public static final int NAME_SYSTEM_TYPE = CODE_215;
090        public static final int SERVICE_READY = CODE_220;
091        public static final int SERVICE_CLOSING_CONTROL_CONNECTION = CODE_221;
092        public static final int DATA_CONNECTION_OPEN = CODE_225;
093        public static final int CLOSING_DATA_CONNECTION = CODE_226;
094        public static final int ENTERING_PASSIVE_MODE = CODE_227;
095        /** @since 2.2 */
096        public static final int ENTERING_EPSV_MODE = CODE_229;
097        public static final int USER_LOGGED_IN = CODE_230;
098        public static final int FILE_ACTION_OK = CODE_250;
099        public static final int PATHNAME_CREATED = CODE_257;
100        public static final int NEED_PASSWORD = CODE_331;
101        public static final int NEED_ACCOUNT = CODE_332;
102        public static final int FILE_ACTION_PENDING = CODE_350;
103        public static final int SERVICE_NOT_AVAILABLE = CODE_421;
104        public static final int CANNOT_OPEN_DATA_CONNECTION = CODE_425;
105        public static final int TRANSFER_ABORTED = CODE_426;
106        public static final int FILE_ACTION_NOT_TAKEN = CODE_450;
107        public static final int ACTION_ABORTED = CODE_451;
108        public static final int INSUFFICIENT_STORAGE = CODE_452;
109        public static final int UNRECOGNIZED_COMMAND = CODE_500;
110        public static final int SYNTAX_ERROR_IN_ARGUMENTS = CODE_501;
111        public static final int COMMAND_NOT_IMPLEMENTED = CODE_502;
112        public static final int BAD_COMMAND_SEQUENCE = CODE_503;
113        public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = CODE_504;
114        public static final int NOT_LOGGED_IN = CODE_530;
115        public static final int NEED_ACCOUNT_FOR_STORING_FILES = CODE_532;
116        public static final int FILE_UNAVAILABLE = CODE_550;
117        public static final int PAGE_TYPE_UNKNOWN = CODE_551;
118        public static final int STORAGE_ALLOCATION_EXCEEDED = CODE_552;
119        public static final int FILE_NAME_NOT_ALLOWED = CODE_553;
120        
121        // FTPS Reply Codes
122        /** @since 2.0 */
123        public static final int CODE_234 = 234;
124        /** @since 2.0 */
125        public static final int CODE_235 = 235;
126        /** @since 2.0 */
127        public static final int CODE_334 = 334;
128        /** @since 2.0 */
129        public static final int CODE_335 = 335;
130        /** @since 2.0 */
131        public static final int CODE_431 = 431;
132        /** @since 2.2 */
133        public static final int CODE_522 = 522;
134        /** @since 2.0 */
135        public static final int CODE_533 = 533;
136        /** @since 2.0 */
137        public static final int CODE_534 = 534;
138        /** @since 2.0 */
139        public static final int CODE_535 = 535;
140        /** @since 2.0 */
141        public static final int CODE_536 = 536;
142        
143        /** @since 2.0 */
144        public static final int SECURITY_DATA_EXCHANGE_COMPLETE = CODE_234;
145        /** @since 2.0 */
146        public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = CODE_235;
147        /** @since 2.0 */
148        public static final int SECURITY_MECHANISM_IS_OK = CODE_334;
149        /** @since 2.0 */
150        public static final int SECURITY_DATA_IS_ACCEPTABLE = CODE_335;
151        /** @since 2.0 */
152        public static final int UNAVAILABLE_RESOURCE = CODE_431;
153        /** @since 2.2 */
154        public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = CODE_522;
155        /** @since 2.0 */
156        public static final int DENIED_FOR_POLICY_REASONS = CODE_533;
157        /** @since 2.0 */
158        public static final int REQUEST_DENIED = CODE_534;
159        /** @since 2.0 */
160        public static final int FAILED_SECURITY_CHECK = CODE_535;
161        /** @since 2.0 */
162        public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = CODE_536;
163        
164        // IPv6 error codes
165        // Note this is also used as an FTPS error code reply
166        /** @since 2.2 */
167        public static final int EXTENDED_PORT_FAILURE = CODE_522;
168    
169        // Cannot be instantiated
170        private FTPReply()
171        {}
172    
173        /***
174         * Determine if a reply code is a positive preliminary response.  All
175         * codes beginning with a 1 are positive preliminary responses.
176         * Postitive preliminary responses are used to indicate tentative success.
177         * No further commands can be issued to the FTP server after a positive
178         * preliminary response until a follow up response is received from the
179         * server.
180         * <p>
181         * @param reply  The reply code to test.
182         * @return True if a reply code is a postive preliminary response, false
183         *         if not.
184         ***/
185        public static boolean isPositivePreliminary(int reply)
186        {
187            return (reply >= 100 && reply < 200);
188        }
189    
190        /***
191         * Determine if a reply code is a positive completion response.  All
192         * codes beginning with a 2 are positive completion responses.
193         * The FTP server will send a positive completion response on the final
194         * successful completion of a command.
195         * <p>
196         * @param reply  The reply code to test.
197         * @return True if a reply code is a postive completion response, false
198         *         if not.
199         ***/
200        public static boolean isPositiveCompletion(int reply)
201        {
202            return (reply >= 200 && reply < 300);
203        }
204    
205        /***
206         * Determine if a reply code is a positive intermediate response.  All
207         * codes beginning with a 3 are positive intermediate responses.
208         * The FTP server will send a positive intermediate response on the
209         * successful completion of one part of a multi-part sequence of
210         * commands.  For example, after a successful USER command, a positive
211         * intermediate response will be sent to indicate that the server is
212         * ready for the PASS command.
213         * <p>
214         * @param reply  The reply code to test.
215         * @return True if a reply code is a postive intermediate response, false
216         *         if not.
217         ***/
218        public static boolean isPositiveIntermediate(int reply)
219        {
220            return (reply >= 300 && reply < 400);
221        }
222    
223        /***
224         * Determine if a reply code is a negative transient response.  All
225         * codes beginning with a 4 are negative transient responses.
226         * The FTP server will send a negative transient response on the
227         * failure of a command that can be reattempted with success.
228         * <p>
229         * @param reply  The reply code to test.
230         * @return True if a reply code is a negative transient response, false
231         *         if not.
232         ***/
233        public static boolean isNegativeTransient(int reply)
234        {
235            return (reply >= 400 && reply < 500);
236        }
237    
238        /***
239         * Determine if a reply code is a negative permanent response.  All
240         * codes beginning with a 5 are negative permanent responses.
241         * The FTP server will send a negative permanent response on the
242         * failure of a command that cannot be reattempted with success.
243         * <p>
244         * @param reply  The reply code to test.
245         * @return True if a reply code is a negative permanent response, false
246         *         if not.
247         ***/
248        public static boolean isNegativePermanent(int reply)
249        {
250            return (reply >= 500 && reply < 600);
251        }
252    
253    }