FTPCommand.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.  * FTPCommand stores a set of constants for FTP command 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. For those who think in terms of the actual FTP commands, a set of constants such as
  21.  * {@link #USER USER } are provided where the constant name is the same as the FTP command.
  22.  *
  23.  * @deprecated use {@link FTPCmd} instead
  24.  */
  25. @Deprecated
  26. public final class FTPCommand {

  27.     /** Command code {@value}. */
  28.     public static final int USER = 0;

  29.     /** Command code {@value}. */
  30.     public static final int PASS = 1;

  31.     /** Command code {@value}. */
  32.     public static final int ACCT = 2;

  33.     /** Command code {@value}. */
  34.     public static final int CWD = 3;

  35.     /** Command code {@value}. */
  36.     public static final int CDUP = 4;

  37.     /** Command code {@value}. */
  38.     public static final int SMNT = 5;

  39.     /** Command code {@value}. */
  40.     public static final int REIN = 6;

  41.     /** Command code {@value}. */
  42.     public static final int QUIT = 7;

  43.     /** Command code {@value}. */
  44.     public static final int PORT = 8;

  45.     /** Command code {@value}. */
  46.     public static final int PASV = 9;

  47.     /** Command code {@value}. */
  48.     public static final int TYPE = 10;

  49.     /** Command code {@value}. */
  50.     public static final int STRU = 11;

  51.     /** Command code {@value}. */
  52.     public static final int MODE = 12;

  53.     /** Command code {@value}. */
  54.     public static final int RETR = 13;

  55.     /** Command code {@value}. */
  56.     public static final int STOR = 14;

  57.     /** Command code {@value}. */

  58.     /** Command code {@value}. */
  59.     public static final int STOU = 15;

  60.     /** Command code {@value}. */
  61.     public static final int APPE = 16;

  62.     /** Command code {@value}. */

  63.     /** Command code {@value}. */
  64.     public static final int ALLO = 17;

  65.     /** Command code {@value}. */
  66.     public static final int REST = 18;

  67.     /** Command code {@value}. */
  68.     public static final int RNFR = 19;

  69.     /** Command code {@value}. */
  70.     public static final int RNTO = 20;

  71.     /** Command code {@value}. */
  72.     public static final int ABOR = 21;

  73.     /** Command code {@value}. */
  74.     public static final int DELE = 22;

  75.     /** Command code {@value}. */
  76.     public static final int RMD = 23;

  77.     /** Command code {@value}. */
  78.     public static final int MKD = 24;

  79.     /** Command code {@value}. */
  80.     public static final int PWD = 25;

  81.     /** Command code {@value}. */
  82.     public static final int LIST = 26;

  83.     /** Command code {@value}. */
  84.     public static final int NLST = 27;

  85.     /** Command code {@value}. */
  86.     public static final int SITE = 28;

  87.     /** Command code {@value}. */
  88.     public static final int SYST = 29;

  89.     /** Command code {@value}. */
  90.     public static final int STAT = 30;

  91.     /** Command code {@value}. */

  92.     /** Command code {@value}. */
  93.     public static final int HELP = 31;

  94.     /** Command code {@value}. */
  95.     public static final int NOOP = 32;

  96.     /**
  97.      * Command code {@value}.
  98.      *
  99.      * @since 2.0
  100.      */
  101.     public static final int MDTM = 33;

  102.     /**
  103.      * Command code {@value}.
  104.      *
  105.      * @since 2.2
  106.      */
  107.     public static final int FEAT = 34;

  108.     /**
  109.      * Command code {@value}.
  110.      *
  111.      * @since 2.0
  112.      */
  113.     public static final int MFMT = 35;

  114.     /**
  115.      * Command code {@value}.
  116.      *
  117.      * @since 2.0
  118.      */
  119.     public static final int EPSV = 36;

  120.     /**
  121.      * Command code {@value}.
  122.      *
  123.      * @since 2.0
  124.      */
  125.     public static final int EPRT = 37;

  126.     /**
  127.      * Machine parseable list for a directory.
  128.      *
  129.      * @since 3.0
  130.      */
  131.     public static final int MLSD = 38;

  132.     /**
  133.      * Machine parseable list for a single file.
  134.      *
  135.      * @since 3.0
  136.      */
  137.     public static final int MLST = 39;

  138.     // Must agree with final entry above; used to check array size
  139.     private static final int LAST = MLST;

  140.     /** Alias for {@value}. */
  141.     public static final int USERNAME = USER;

  142.     /** Alias for {@value}. */
  143.     public static final int PASSWORD = PASS;

  144.     /** Alias for {@value}. */
  145.     public static final int ACCOUNT = ACCT;

  146.     /** Alias for {@value}. */
  147.     public static final int CHANGE_WORKING_DIRECTORY = CWD;

  148.     /** Alias for {@value}. */
  149.     public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;

  150.     /** Alias for {@value}. */
  151.     public static final int STRUCTURE_MOUNT = SMNT;

  152.     /** Alias for {@value}. */
  153.     public static final int REINITIALIZE = REIN;

  154.     /** Alias for {@value}. */
  155.     public static final int LOGOUT = QUIT;

  156.     /** Alias for {@value}. */
  157.     public static final int DATA_PORT = PORT;

  158.     /** Alias for {@value}. */
  159.     public static final int PASSIVE = PASV;

  160.     /** Alias for {@value}. */
  161.     public static final int REPRESENTATION_TYPE = TYPE;

  162.     /** Alias for {@value}. */
  163.     public static final int FILE_STRUCTURE = STRU;

  164.     /** Alias for {@value}. */
  165.     public static final int TRANSFER_MODE = MODE;

  166.     /** Alias for {@value}. */
  167.     public static final int RETRIEVE = RETR;

  168.     /** Alias for {@value}. */
  169.     public static final int STORE = STOR;

  170.     /** Alias for {@value}. */
  171.     public static final int STORE_UNIQUE = STOU;

  172.     /** Alias for {@value}. */
  173.     public static final int APPEND = APPE;

  174.     /** Alias for {@value}. */
  175.     public static final int ALLOCATE = ALLO;

  176.     /** Alias for {@value}. */
  177.     public static final int RESTART = REST;

  178.     /** Alias for {@value}. */
  179.     public static final int RENAME_FROM = RNFR;

  180.     /** Alias for {@value}. */
  181.     public static final int RENAME_TO = RNTO;

  182.     /** Alias for {@value}. */
  183.     public static final int ABORT = ABOR;

  184.     /** Alias for {@value}. */
  185.     public static final int DELETE = DELE;

  186.     /** Alias for {@value}. */
  187.     public static final int REMOVE_DIRECTORY = RMD;

  188.     /** Alias for {@value}. */
  189.     public static final int MAKE_DIRECTORY = MKD;

  190.     /** Alias for {@value}. */
  191.     public static final int PRINT_WORKING_DIRECTORY = PWD;

  192.     // public static final int LIST = LIST;

  193.     /** Alias for {@value}. */
  194.     public static final int NAME_LIST = NLST;

  195.     /** Alias for {@value}. */
  196.     public static final int SITE_PARAMETERS = SITE;

  197.     /** Alias for {@value}. */
  198.     public static final int SYSTEM = SYST;

  199.     /** Alias for {@value}. */
  200.     public static final int STATUS = STAT;

  201.     // public static final int HELP = HELP;
  202.     // public static final int NOOP = NOOP;

  203.     /**
  204.      * Alias for {@value}.
  205.      * @since 2.0
  206.      */
  207.     public static final int MOD_TIME = MDTM;

  208.     /**
  209.      * Alias for {@value}.
  210.      * @since 2.2
  211.      */
  212.     public static final int FEATURES = FEAT;

  213.     /**
  214.      * Alias for {@value}.
  215.      * @since 2.2
  216.      */
  217.     public static final int GET_MOD_TIME = MDTM;

  218.     /**
  219.      * Alias for {@value}.
  220.      * @since 2.2
  221.      */
  222.     public static final int SET_MOD_TIME = MFMT;

  223.     private static final String[] COMMANDS = { "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT", "PASV", "TYPE", "STRU", "MODE", "RETR",
  224.             "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP",
  225.             "MDTM", "FEAT", "MFMT", "EPSV", "EPRT", "MLSD", "MLST" };

  226.     /**
  227.      * Default access needed for Unit test.
  228.      */
  229.     static void checkArray() {
  230.         final int expectedLength = LAST + 1;
  231.         if (COMMANDS.length != expectedLength) {
  232.             throw new IllegalStateException("Incorrect COMMANDS array. Should have length " + expectedLength + " found " + COMMANDS.length);
  233.         }
  234.     }

  235.     /**
  236.      * Retrieve the FTP protocol command string corresponding to a specified command code.
  237.      *
  238.      * @param command The command code.
  239.      * @return The FTP protcol command string corresponding to a specified command code.
  240.      */
  241.     public static String getCommand(final int command) {
  242.         return COMMANDS[command];
  243.     }

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