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.
25   * <p>
26   * TODO replace with an enum
27   ***/
28  
29  public final class FTPReply
30  {
31  
32      public static final int RESTART_MARKER = 110;
33      public static final int SERVICE_NOT_READY = 120;
34      public static final int DATA_CONNECTION_ALREADY_OPEN = 125;
35      public static final int FILE_STATUS_OK = 150;
36      public static final int COMMAND_OK = 200;
37      public static final int COMMAND_IS_SUPERFLUOUS = 202;
38      public static final int SYSTEM_STATUS = 211;
39      public static final int DIRECTORY_STATUS = 212;
40      public static final int FILE_STATUS = 213;
41      public static final int HELP_MESSAGE = 214;
42      public static final int NAME_SYSTEM_TYPE = 215;
43      public static final int SERVICE_READY = 220;
44      public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221;
45      public static final int DATA_CONNECTION_OPEN = 225;
46      public static final int CLOSING_DATA_CONNECTION = 226;
47      public static final int ENTERING_PASSIVE_MODE = 227;
48      /** @since 2.2 */
49      public static final int ENTERING_EPSV_MODE = 229;
50      public static final int USER_LOGGED_IN = 230;
51      public static final int FILE_ACTION_OK = 250;
52      public static final int PATHNAME_CREATED = 257;
53      public static final int NEED_PASSWORD = 331;
54      public static final int NEED_ACCOUNT = 332;
55      public static final int FILE_ACTION_PENDING = 350;
56      public static final int SERVICE_NOT_AVAILABLE = 421;
57      public static final int CANNOT_OPEN_DATA_CONNECTION = 425;
58      public static final int TRANSFER_ABORTED = 426;
59      public static final int FILE_ACTION_NOT_TAKEN = 450;
60      public static final int ACTION_ABORTED = 451;
61      public static final int INSUFFICIENT_STORAGE = 452;
62      public static final int UNRECOGNIZED_COMMAND = 500;
63      public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
64      public static final int COMMAND_NOT_IMPLEMENTED = 502;
65      public static final int BAD_COMMAND_SEQUENCE = 503;
66      public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
67      public static final int NOT_LOGGED_IN = 530;
68      public static final int NEED_ACCOUNT_FOR_STORING_FILES = 532;
69      public static final int FILE_UNAVAILABLE = 550;
70      public static final int PAGE_TYPE_UNKNOWN = 551;
71      public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
72      public static final int FILE_NAME_NOT_ALLOWED = 553;
73  
74      // FTPS Reply Codes
75  
76      /** @since 2.0 */
77      public static final int SECURITY_DATA_EXCHANGE_COMPLETE = 234;
78      /** @since 2.0 */
79      public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = 235;
80      /** @since 2.0 */
81      public static final int SECURITY_MECHANISM_IS_OK = 334;
82      /** @since 2.0 */
83      public static final int SECURITY_DATA_IS_ACCEPTABLE = 335;
84      /** @since 2.0 */
85      public static final int UNAVAILABLE_RESOURCE = 431;
86      /** @since 2.2 */
87      public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = 522;
88      /** @since 2.0 */
89      public static final int DENIED_FOR_POLICY_REASONS = 533;
90      /** @since 2.0 */
91      public static final int REQUEST_DENIED = 534;
92      /** @since 2.0 */
93      public static final int FAILED_SECURITY_CHECK = 535;
94      /** @since 2.0 */
95      public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = 536;
96  
97      // IPv6 error codes
98      // Note this is also used as an FTPS error code reply
99      /** @since 2.2 */
100     public static final int EXTENDED_PORT_FAILURE = 522;
101 
102     // Cannot be instantiated
103     private FTPReply()
104     {}
105 
106     /***
107      * Determine if a reply code is a positive preliminary response.  All
108      * codes beginning with a 1 are positive preliminary responses.
109      * Postitive preliminary responses are used to indicate tentative success.
110      * No further commands can be issued to the FTP server after a positive
111      * preliminary response until a follow up response is received from the
112      * server.
113      * <p>
114      * @param reply  The reply code to test.
115      * @return True if a reply code is a postive preliminary response, false
116      *         if not.
117      ***/
118     public static boolean isPositivePreliminary(int reply)
119     {
120         return (reply >= 100 && reply < 200);
121     }
122 
123     /***
124      * Determine if a reply code is a positive completion response.  All
125      * codes beginning with a 2 are positive completion responses.
126      * The FTP server will send a positive completion response on the final
127      * successful completion of a command.
128      * <p>
129      * @param reply  The reply code to test.
130      * @return True if a reply code is a postive completion response, false
131      *         if not.
132      ***/
133     public static boolean isPositiveCompletion(int reply)
134     {
135         return (reply >= 200 && reply < 300);
136     }
137 
138     /***
139      * Determine if a reply code is a positive intermediate response.  All
140      * codes beginning with a 3 are positive intermediate responses.
141      * The FTP server will send a positive intermediate response on the
142      * successful completion of one part of a multi-part sequence of
143      * commands.  For example, after a successful USER command, a positive
144      * intermediate response will be sent to indicate that the server is
145      * ready for the PASS command.
146      * <p>
147      * @param reply  The reply code to test.
148      * @return True if a reply code is a postive intermediate response, false
149      *         if not.
150      ***/
151     public static boolean isPositiveIntermediate(int reply)
152     {
153         return (reply >= 300 && reply < 400);
154     }
155 
156     /***
157      * Determine if a reply code is a negative transient response.  All
158      * codes beginning with a 4 are negative transient responses.
159      * The FTP server will send a negative transient response on the
160      * failure of a command that can be reattempted with success.
161      * <p>
162      * @param reply  The reply code to test.
163      * @return True if a reply code is a negative transient response, false
164      *         if not.
165      ***/
166     public static boolean isNegativeTransient(int reply)
167     {
168         return (reply >= 400 && reply < 500);
169     }
170 
171     /***
172      * Determine if a reply code is a negative permanent response.  All
173      * codes beginning with a 5 are negative permanent responses.
174      * The FTP server will send a negative permanent response on the
175      * failure of a command that cannot be reattempted with success.
176      * <p>
177      * @param reply  The reply code to test.
178      * @return True if a reply code is a negative permanent response, false
179      *         if not.
180      ***/
181     public static boolean isNegativePermanent(int reply)
182     {
183         return (reply >= 500 && reply < 600);
184     }
185 
186     /**
187      * Determine if a reply code is a protected response.
188      * @param reply  The reply code to test.
189      * @return True if a reply code is a protected response, false
190      *         if not.
191      * @since 3.0
192      */
193     public static boolean isProtectedReplyCode(int reply)
194     {
195         // actually, only 3 protected reply codes are
196         // defined in RFC 2228: 631, 632 and 633.
197         return (reply >= 600 && reply < 700);
198     }
199 
200 
201 }