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
018package org.apache.commons.net.ftp;
019
020/**
021 * FTPReply stores a set of constants for FTP reply codes. To interpret the meaning of the codes, familiarity with RFC 959 is assumed. The mnemonic constant
022 * names are transcriptions from the code descriptions of RFC 959.
023 * <p>
024 * TODO replace with an enum
025 * </p>
026 */
027public final class FTPReply {
028
029    /** Reply code {@value}. */
030    public static final int RESTART_MARKER = 110;
031
032    /** Reply code {@value}. */
033    public static final int SERVICE_NOT_READY = 120;
034
035    /** Reply code {@value}. */
036    public static final int DATA_CONNECTION_ALREADY_OPEN = 125;
037
038    /** Reply code {@value}. */
039    public static final int FILE_STATUS_OK = 150;
040
041    /** Reply code {@value}. */
042    public static final int COMMAND_OK = 200;
043
044    /** Reply code {@value}. */
045    public static final int COMMAND_IS_SUPERFLUOUS = 202;
046
047    /** Reply code {@value}. */
048    public static final int SYSTEM_STATUS = 211;
049
050    /** Reply code {@value}. */
051    public static final int DIRECTORY_STATUS = 212;
052
053    /** Reply code {@value}. */
054    public static final int FILE_STATUS = 213;
055
056    /** Reply code {@value}. */
057    public static final int HELP_MESSAGE = 214;
058
059    /** Reply code {@value}. */
060    public static final int NAME_SYSTEM_TYPE = 215;
061
062    /** Reply code {@value}. */
063    public static final int SERVICE_READY = 220;
064
065    /** Reply code {@value}. */
066    public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221;
067
068    /** Reply code {@value}. */
069    public static final int DATA_CONNECTION_OPEN = 225;
070
071    /** Reply code {@value}. */
072    public static final int CLOSING_DATA_CONNECTION = 226;
073
074    /** Reply code {@value}. */
075    public static final int ENTERING_PASSIVE_MODE = 227;
076
077    /**
078     * Reply code {@value}.
079     *
080     * @since 2.2
081     */
082    public static final int ENTERING_EPSV_MODE = 229;
083
084    /** Reply code {@value}. */
085    public static final int USER_LOGGED_IN = 230;
086
087    /** Reply code {@value}. */
088    public static final int FILE_ACTION_OK = 250;
089
090    /** Reply code {@value}. */
091    public static final int PATHNAME_CREATED = 257;
092
093    /** Reply code {@value}. */
094    public static final int NEED_PASSWORD = 331;
095
096    /** Reply code {@value}. */
097    public static final int NEED_ACCOUNT = 332;
098
099    /** Reply code {@value}. */
100    public static final int FILE_ACTION_PENDING = 350;
101
102    /** Reply code {@value}. */
103    public static final int SERVICE_NOT_AVAILABLE = 421;
104
105    /** Reply code {@value}. */
106    public static final int CANNOT_OPEN_DATA_CONNECTION = 425;
107
108    /** Reply code {@value}. */
109    public static final int TRANSFER_ABORTED = 426;
110
111    /** Reply code {@value}. */
112    public static final int FILE_ACTION_NOT_TAKEN = 450;
113
114    /** Reply code {@value}. */
115    public static final int ACTION_ABORTED = 451;
116
117    /** Reply code {@value}. */
118    public static final int INSUFFICIENT_STORAGE = 452;
119
120    /** Reply code {@value}. */
121    public static final int UNRECOGNIZED_COMMAND = 500;
122
123    /** Reply code {@value}. */
124    public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
125
126    /** Reply code {@value}. */
127    public static final int COMMAND_NOT_IMPLEMENTED = 502;
128
129    /** Reply code {@value}. */
130    public static final int BAD_COMMAND_SEQUENCE = 503;
131
132    /** Reply code {@value}. */
133    public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
134
135    /** Reply code {@value}. */
136    public static final int NOT_LOGGED_IN = 530;
137
138    /** Reply code {@value}. */
139    public static final int NEED_ACCOUNT_FOR_STORING_FILES = 532;
140
141    /** Reply code {@value}. */
142    public static final int FILE_UNAVAILABLE = 550;
143
144    /** Reply code {@value}. */
145    public static final int PAGE_TYPE_UNKNOWN = 551;
146
147    /** Reply code {@value}. */
148    public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
149
150    /** Reply code {@value}. */
151    public static final int FILE_NAME_NOT_ALLOWED = 553;
152
153    // FTPS Reply Codes
154
155    /**
156     * FTPS reply code {@value}
157     *
158     * @since 2.0
159     */
160    public static final int SECURITY_DATA_EXCHANGE_COMPLETE = 234;
161
162    /**
163     * FTPS reply code {@value}
164     *
165     * @since 2.0
166     */
167    public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = 235;
168
169    /**
170     * FTPS reply code {@value}
171     *
172     * @since 2.0
173     */
174    public static final int SECURITY_MECHANISM_IS_OK = 334;
175
176    /**
177     * FTPS reply code {@value}
178     *
179     * @since 2.0
180     */
181    public static final int SECURITY_DATA_IS_ACCEPTABLE = 335;
182
183    /**
184     * FTPS reply code {@value}
185     *
186     * @since 2.0
187     */
188    public static final int UNAVAILABLE_RESOURCE = 431;
189
190    /**
191     * FTPS reply code {@value}
192     *
193     * @since 2.0
194     */
195    public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = 522;
196
197    /**
198     * FTPS reply code {@value}
199     *
200     * @since 2.0
201     */
202    public static final int DENIED_FOR_POLICY_REASONS = 533;
203
204    /**
205     * FTPS reply code {@value}
206     *
207     * @since 2.0
208     */
209    public static final int REQUEST_DENIED = 534;
210
211    /**
212     * FTPS reply code {@value}
213     *
214     * @since 2.0
215     */
216    public static final int FAILED_SECURITY_CHECK = 535;
217
218    /**
219     * FTPS reply code {@value}
220     *
221     * @since 2.0
222     */
223    public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = 536;
224
225    /**
226     * IPv6 error codes.
227     * <p>
228     * Note this is also used as an FTPS error code reply
229     * </p>
230     *
231     * @since 2.2
232     */
233    public static final int EXTENDED_PORT_FAILURE = 522;
234
235    /**
236     * Tests if a reply code is a negative permanent response. All codes beginning with a 5 are negative permanent responses. The FTP server will send a
237     * negative permanent response on the failure of a command that cannot be reattempted with success.
238     *
239     * @param reply The reply code to test.
240     * @return True if a reply code is a negative permanent response, false if not.
241     */
242    public static boolean isNegativePermanent(final int reply) {
243        return reply >= 500 && reply < 600;
244    }
245
246    /**
247     * Tests if a reply code is a negative transient response. All codes beginning with a 4 are negative transient responses. The FTP server will send a
248     * negative transient response on the failure of a command that can be reattempted with success.
249     *
250     * @param reply The reply code to test.
251     * @return True if a reply code is a negative transient response, false if not.
252     */
253    public static boolean isNegativeTransient(final int reply) {
254        return reply >= 400 && reply < 500;
255    }
256
257    /**
258     * Tests if a reply code is a positive completion response. All codes beginning with a 2 are positive completion responses. The FTP server will send a
259     * positive completion response on the final successful completion of a command.
260     *
261     * @param reply The reply code to test.
262     * @return True if a reply code is a positive completion response, false if not.
263     */
264    public static boolean isPositiveCompletion(final int reply) {
265        return reply >= 200 && reply < 300;
266    }
267
268    /**
269     * Tests if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The FTP server will send
270     * a positive intermediate response on the successful completion of one part of a multipart sequence of commands. For example, after a successful USER
271     * command, a positive intermediate response will be sent to indicate that the server is ready for the PASS command.
272     *
273     * @param reply The reply code to test.
274     * @return True if a reply code is a positive intermediate response, false if not.
275     */
276    public static boolean isPositiveIntermediate(final int reply) {
277        return reply >= 300 && reply < 400;
278    }
279
280    /**
281     * Tests if a reply code is a positive preliminary response. All codes beginning with a 1 are positive preliminary responses. Postitive preliminary
282     * responses are used to indicate tentative success. No further commands can be issued to the FTP server after a positive preliminary response until a
283     * follow-up response is received from the server.
284     *
285     * @param reply The reply code to test.
286     * @return True if a reply code is a positive preliminary response, false if not.
287     */
288    public static boolean isPositivePreliminary(final int reply) {
289        return reply >= 100 && reply < 200;
290    }
291
292    /**
293     * Tests if a reply code is a protected response.
294     *
295     * @param reply The reply code to test.
296     * @return True if a reply code is a protected response, false if not.
297     * @since 3.0
298     */
299    public static boolean isProtectedReplyCode(final int reply) {
300        // actually, only 3 protected reply codes are
301        // defined in RFC 2228: 631, 632 and 633.
302        return reply >= 600 && reply < 700;
303    }
304
305    /** Cannot be instantiated. */
306    private FTPReply() {
307    }
308
309}