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 * https://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 the meaning of the codes, familiarity with RFC 959 is assumed. The mnemonic constant
22 * names are transcriptions from the code descriptions of RFC 959.
23 * <p>
24 * TODO replace with an enum
25 * </p>
26 */
27 public final class FTPReply {
28
29 /** Reply code {@value}. */
30 public static final int RESTART_MARKER = 110;
31
32 /** Reply code {@value}. */
33 public static final int SERVICE_NOT_READY = 120;
34
35 /** Reply code {@value}. */
36 public static final int DATA_CONNECTION_ALREADY_OPEN = 125;
37
38 /** Reply code {@value}. */
39 public static final int FILE_STATUS_OK = 150;
40
41 /** Reply code {@value}. */
42 public static final int COMMAND_OK = 200;
43
44 /** Reply code {@value}. */
45 public static final int COMMAND_IS_SUPERFLUOUS = 202;
46
47 /** Reply code {@value}. */
48 public static final int SYSTEM_STATUS = 211;
49
50 /** Reply code {@value}. */
51 public static final int DIRECTORY_STATUS = 212;
52
53 /** Reply code {@value}. */
54 public static final int FILE_STATUS = 213;
55
56 /** Reply code {@value}. */
57 public static final int HELP_MESSAGE = 214;
58
59 /** Reply code {@value}. */
60 public static final int NAME_SYSTEM_TYPE = 215;
61
62 /** Reply code {@value}. */
63 public static final int SERVICE_READY = 220;
64
65 /** Reply code {@value}. */
66 public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221;
67
68 /** Reply code {@value}. */
69 public static final int DATA_CONNECTION_OPEN = 225;
70
71 /** Reply code {@value}. */
72 public static final int CLOSING_DATA_CONNECTION = 226;
73
74 /** Reply code {@value}. */
75 public static final int ENTERING_PASSIVE_MODE = 227;
76
77 /**
78 * Reply code {@value}.
79 *
80 * @since 2.2
81 */
82 public static final int ENTERING_EPSV_MODE = 229;
83
84 /** Reply code {@value}. */
85 public static final int USER_LOGGED_IN = 230;
86
87 /** Reply code {@value}. */
88 public static final int FILE_ACTION_OK = 250;
89
90 /** Reply code {@value}. */
91 public static final int PATHNAME_CREATED = 257;
92
93 /** Reply code {@value}. */
94 public static final int NEED_PASSWORD = 331;
95
96 /** Reply code {@value}. */
97 public static final int NEED_ACCOUNT = 332;
98
99 /** 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 }