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 */
026
027public final class FTPReply {
028
029    public static final int RESTART_MARKER = 110;
030    public static final int SERVICE_NOT_READY = 120;
031    public static final int DATA_CONNECTION_ALREADY_OPEN = 125;
032    public static final int FILE_STATUS_OK = 150;
033    public static final int COMMAND_OK = 200;
034    public static final int COMMAND_IS_SUPERFLUOUS = 202;
035    public static final int SYSTEM_STATUS = 211;
036    public static final int DIRECTORY_STATUS = 212;
037    public static final int FILE_STATUS = 213;
038    public static final int HELP_MESSAGE = 214;
039    public static final int NAME_SYSTEM_TYPE = 215;
040    public static final int SERVICE_READY = 220;
041    public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221;
042    public static final int DATA_CONNECTION_OPEN = 225;
043    public static final int CLOSING_DATA_CONNECTION = 226;
044    public static final int ENTERING_PASSIVE_MODE = 227;
045    /** @since 2.2 */
046    public static final int ENTERING_EPSV_MODE = 229;
047    public static final int USER_LOGGED_IN = 230;
048    public static final int FILE_ACTION_OK = 250;
049    public static final int PATHNAME_CREATED = 257;
050    public static final int NEED_PASSWORD = 331;
051    public static final int NEED_ACCOUNT = 332;
052    public static final int FILE_ACTION_PENDING = 350;
053    public static final int SERVICE_NOT_AVAILABLE = 421;
054    public static final int CANNOT_OPEN_DATA_CONNECTION = 425;
055    public static final int TRANSFER_ABORTED = 426;
056    public static final int FILE_ACTION_NOT_TAKEN = 450;
057    public static final int ACTION_ABORTED = 451;
058    public static final int INSUFFICIENT_STORAGE = 452;
059    public static final int UNRECOGNIZED_COMMAND = 500;
060    public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
061    public static final int COMMAND_NOT_IMPLEMENTED = 502;
062    public static final int BAD_COMMAND_SEQUENCE = 503;
063    public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
064    public static final int NOT_LOGGED_IN = 530;
065    public static final int NEED_ACCOUNT_FOR_STORING_FILES = 532;
066    public static final int FILE_UNAVAILABLE = 550;
067    public static final int PAGE_TYPE_UNKNOWN = 551;
068    public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
069    public static final int FILE_NAME_NOT_ALLOWED = 553;
070
071    // FTPS Reply Codes
072
073    /** @since 2.0 */
074    public static final int SECURITY_DATA_EXCHANGE_COMPLETE = 234;
075    /** @since 2.0 */
076    public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = 235;
077    /** @since 2.0 */
078    public static final int SECURITY_MECHANISM_IS_OK = 334;
079    /** @since 2.0 */
080    public static final int SECURITY_DATA_IS_ACCEPTABLE = 335;
081    /** @since 2.0 */
082    public static final int UNAVAILABLE_RESOURCE = 431;
083    /** @since 2.2 */
084    public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = 522;
085    /** @since 2.0 */
086    public static final int DENIED_FOR_POLICY_REASONS = 533;
087    /** @since 2.0 */
088    public static final int REQUEST_DENIED = 534;
089    /** @since 2.0 */
090    public static final int FAILED_SECURITY_CHECK = 535;
091    /** @since 2.0 */
092    public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = 536;
093
094    // IPv6 error codes
095    // Note this is also used as an FTPS error code reply
096    /** @since 2.2 */
097    public static final int EXTENDED_PORT_FAILURE = 522;
098
099    /**
100     * Determine 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
101     * negative permanent response on the failure of a command that cannot be reattempted with success.
102     *
103     * @param reply The reply code to test.
104     * @return True if a reply code is a negative permanent response, false if not.
105     */
106    public static boolean isNegativePermanent(final int reply) {
107        return reply >= 500 && reply < 600;
108    }
109
110    /**
111     * Determine 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
112     * negative transient response on the failure of a command that can be reattempted with success.
113     *
114     * @param reply The reply code to test.
115     * @return True if a reply code is a negative transient response, false if not.
116     */
117    public static boolean isNegativeTransient(final int reply) {
118        return reply >= 400 && reply < 500;
119    }
120
121    /**
122     * Determine 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
123     * positive completion response on the final successful completion of a command.
124     *
125     * @param reply The reply code to test.
126     * @return True if a reply code is a positive completion response, false if not.
127     */
128    public static boolean isPositiveCompletion(final int reply) {
129        return reply >= 200 && reply < 300;
130    }
131
132    /**
133     * Determine if a reply code is a positive intermediate response. All codes beginning with a 3 are positive intermediate responses. The FTP server will send
134     * a positive intermediate response on the successful completion of one part of a multi-part sequence of commands. For example, after a successful USER
135     * command, a positive intermediate response will be sent to indicate that the server is ready for the PASS command.
136     *
137     * @param reply The reply code to test.
138     * @return True if a reply code is a positive intermediate response, false if not.
139     */
140    public static boolean isPositiveIntermediate(final int reply) {
141        return reply >= 300 && reply < 400;
142    }
143
144    /**
145     * Determine if a reply code is a positive preliminary response. All codes beginning with a 1 are positive preliminary responses. Postitive preliminary
146     * responses are used to indicate tentative success. No further commands can be issued to the FTP server after a positive preliminary response until a
147     * follow up response is received from the server.
148     *
149     * @param reply The reply code to test.
150     * @return True if a reply code is a positive preliminary response, false if not.
151     */
152    public static boolean isPositivePreliminary(final int reply) {
153        return reply >= 100 && reply < 200;
154    }
155
156    /**
157     * Determine if a reply code is a protected response.
158     *
159     * @param reply The reply code to test.
160     * @return True if a reply code is a protected response, false if not.
161     * @since 3.0
162     */
163    public static boolean isProtectedReplyCode(final int reply) {
164        // actually, only 3 protected reply codes are
165        // defined in RFC 2228: 631, 632 and 633.
166        return reply >= 600 && reply < 700;
167    }
168
169    // Cannot be instantiated
170    private FTPReply() {
171    }
172
173}