FTPReply.java

  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. package org.apache.commons.net.ftp;

  18. /**
  19.  * 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
  20.  * names are transcriptions from the code descriptions of RFC 959.
  21.  * <p>
  22.  * TODO replace with an enum
  23.  * </p>
  24.  */
  25. public final class FTPReply {

  26.     /** Reply code {@value}. */
  27.     public static final int RESTART_MARKER = 110;

  28.     /** Reply code {@value}. */
  29.     public static final int SERVICE_NOT_READY = 120;

  30.     /** Reply code {@value}. */
  31.     public static final int DATA_CONNECTION_ALREADY_OPEN = 125;

  32.     /** Reply code {@value}. */
  33.     public static final int FILE_STATUS_OK = 150;

  34.     /** Reply code {@value}. */
  35.     public static final int COMMAND_OK = 200;

  36.     /** Reply code {@value}. */
  37.     public static final int COMMAND_IS_SUPERFLUOUS = 202;

  38.     /** Reply code {@value}. */
  39.     public static final int SYSTEM_STATUS = 211;

  40.     /** Reply code {@value}. */
  41.     public static final int DIRECTORY_STATUS = 212;

  42.     /** Reply code {@value}. */
  43.     public static final int FILE_STATUS = 213;

  44.     /** Reply code {@value}. */
  45.     public static final int HELP_MESSAGE = 214;

  46.     /** Reply code {@value}. */
  47.     public static final int NAME_SYSTEM_TYPE = 215;

  48.     /** Reply code {@value}. */
  49.     public static final int SERVICE_READY = 220;

  50.     /** Reply code {@value}. */
  51.     public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221;

  52.     /** Reply code {@value}. */
  53.     public static final int DATA_CONNECTION_OPEN = 225;

  54.     /** Reply code {@value}. */
  55.     public static final int CLOSING_DATA_CONNECTION = 226;

  56.     /** Reply code {@value}. */
  57.     public static final int ENTERING_PASSIVE_MODE = 227;

  58.     /**
  59.      * Reply code {@value}.
  60.      *
  61.      * @since 2.2
  62.      */
  63.     public static final int ENTERING_EPSV_MODE = 229;

  64.     /** Reply code {@value}. */
  65.     public static final int USER_LOGGED_IN = 230;

  66.     /** Reply code {@value}. */
  67.     public static final int FILE_ACTION_OK = 250;

  68.     /** Reply code {@value}. */
  69.     public static final int PATHNAME_CREATED = 257;

  70.     /** Reply code {@value}. */
  71.     public static final int NEED_PASSWORD = 331;

  72.     /** Reply code {@value}. */
  73.     public static final int NEED_ACCOUNT = 332;

  74.     /** Reply code {@value}. */
  75.     public static final int FILE_ACTION_PENDING = 350;

  76.     /** Reply code {@value}. */
  77.     public static final int SERVICE_NOT_AVAILABLE = 421;

  78.     /** Reply code {@value}. */
  79.     public static final int CANNOT_OPEN_DATA_CONNECTION = 425;

  80.     /** Reply code {@value}. */
  81.     public static final int TRANSFER_ABORTED = 426;

  82.     /** Reply code {@value}. */
  83.     public static final int FILE_ACTION_NOT_TAKEN = 450;

  84.     /** Reply code {@value}. */
  85.     public static final int ACTION_ABORTED = 451;

  86.     /** Reply code {@value}. */
  87.     public static final int INSUFFICIENT_STORAGE = 452;

  88.     /** Reply code {@value}. */
  89.     public static final int UNRECOGNIZED_COMMAND = 500;

  90.     /** Reply code {@value}. */
  91.     public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;

  92.     /** Reply code {@value}. */
  93.     public static final int COMMAND_NOT_IMPLEMENTED = 502;

  94.     /** Reply code {@value}. */
  95.     public static final int BAD_COMMAND_SEQUENCE = 503;

  96.     /** Reply code {@value}. */
  97.     public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;

  98.     /** Reply code {@value}. */
  99.     public static final int NOT_LOGGED_IN = 530;

  100.     /** Reply code {@value}. */
  101.     public static final int NEED_ACCOUNT_FOR_STORING_FILES = 532;

  102.     /** Reply code {@value}. */
  103.     public static final int FILE_UNAVAILABLE = 550;

  104.     /** Reply code {@value}. */
  105.     public static final int PAGE_TYPE_UNKNOWN = 551;

  106.     /** Reply code {@value}. */
  107.     public static final int STORAGE_ALLOCATION_EXCEEDED = 552;

  108.     /** Reply code {@value}. */
  109.     public static final int FILE_NAME_NOT_ALLOWED = 553;

  110.     // FTPS Reply Codes

  111.     /**
  112.      * FTPS reply code {@value}
  113.      *
  114.      * @since 2.0
  115.      */
  116.     public static final int SECURITY_DATA_EXCHANGE_COMPLETE = 234;

  117.     /**
  118.      * FTPS reply code {@value}
  119.      *
  120.      * @since 2.0
  121.      */
  122.     public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = 235;

  123.     /**
  124.      * FTPS reply code {@value}
  125.      *
  126.      * @since 2.0
  127.      */
  128.     public static final int SECURITY_MECHANISM_IS_OK = 334;

  129.     /**
  130.      * FTPS reply code {@value}
  131.      *
  132.      * @since 2.0
  133.      */
  134.     public static final int SECURITY_DATA_IS_ACCEPTABLE = 335;

  135.     /**
  136.      * FTPS reply code {@value}
  137.      *
  138.      * @since 2.0
  139.      */
  140.     public static final int UNAVAILABLE_RESOURCE = 431;

  141.     /**
  142.      * FTPS reply code {@value}
  143.      *
  144.      * @since 2.0
  145.      */
  146.     public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = 522;

  147.     /**
  148.      * FTPS reply code {@value}
  149.      *
  150.      * @since 2.0
  151.      */
  152.     public static final int DENIED_FOR_POLICY_REASONS = 533;

  153.     /**
  154.      * FTPS reply code {@value}
  155.      *
  156.      * @since 2.0
  157.      */
  158.     public static final int REQUEST_DENIED = 534;

  159.     /**
  160.      * FTPS reply code {@value}
  161.      *
  162.      * @since 2.0
  163.      */
  164.     public static final int FAILED_SECURITY_CHECK = 535;

  165.     /**
  166.      * FTPS reply code {@value}
  167.      *
  168.      * @since 2.0
  169.      */
  170.     public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = 536;

  171.     /**
  172.      * IPv6 error codes.
  173.      * <p>
  174.      * Note this is also used as an FTPS error code reply
  175.      * </p>
  176.      *
  177.      * @since 2.2
  178.      */
  179.     public static final int EXTENDED_PORT_FAILURE = 522;

  180.     /**
  181.      * 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
  182.      * negative permanent response on the failure of a command that cannot be reattempted with success.
  183.      *
  184.      * @param reply The reply code to test.
  185.      * @return True if a reply code is a negative permanent response, false if not.
  186.      */
  187.     public static boolean isNegativePermanent(final int reply) {
  188.         return reply >= 500 && reply < 600;
  189.     }

  190.     /**
  191.      * 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
  192.      * negative transient response on the failure of a command that can be reattempted with success.
  193.      *
  194.      * @param reply The reply code to test.
  195.      * @return True if a reply code is a negative transient response, false if not.
  196.      */
  197.     public static boolean isNegativeTransient(final int reply) {
  198.         return reply >= 400 && reply < 500;
  199.     }

  200.     /**
  201.      * 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
  202.      * positive completion response on the final successful completion of a command.
  203.      *
  204.      * @param reply The reply code to test.
  205.      * @return True if a reply code is a positive completion response, false if not.
  206.      */
  207.     public static boolean isPositiveCompletion(final int reply) {
  208.         return reply >= 200 && reply < 300;
  209.     }

  210.     /**
  211.      * 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
  212.      * a positive intermediate response on the successful completion of one part of a multipart sequence of commands. For example, after a successful USER
  213.      * command, a positive intermediate response will be sent to indicate that the server is ready for the PASS command.
  214.      *
  215.      * @param reply The reply code to test.
  216.      * @return True if a reply code is a positive intermediate response, false if not.
  217.      */
  218.     public static boolean isPositiveIntermediate(final int reply) {
  219.         return reply >= 300 && reply < 400;
  220.     }

  221.     /**
  222.      * Tests if a reply code is a positive preliminary response. All codes beginning with a 1 are positive preliminary responses. Postitive preliminary
  223.      * responses are used to indicate tentative success. No further commands can be issued to the FTP server after a positive preliminary response until a
  224.      * follow-up response is received from the server.
  225.      *
  226.      * @param reply The reply code to test.
  227.      * @return True if a reply code is a positive preliminary response, false if not.
  228.      */
  229.     public static boolean isPositivePreliminary(final int reply) {
  230.         return reply >= 100 && reply < 200;
  231.     }

  232.     /**
  233.      * Tests if a reply code is a protected response.
  234.      *
  235.      * @param reply The reply code to test.
  236.      * @return True if a reply code is a protected response, false if not.
  237.      * @since 3.0
  238.      */
  239.     public static boolean isProtectedReplyCode(final int reply) {
  240.         // actually, only 3 protected reply codes are
  241.         // defined in RFC 2228: 631, 632 and 633.
  242.         return reply >= 600 && reply < 700;
  243.     }

  244.     /** Cannot be instantiated. */
  245.     private FTPReply() {
  246.     }

  247. }