    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 *      https://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 * 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
    022 * 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
    023 * {@link #USER USER} are provided where the constant name is the same as the FTP command.
    024 *
    025 * @deprecated use {@link FTPCmd} instead
    026 */
    027@Deprecated
    028public final class FTPCommand {
    029
    030    /** Command code {@value}. */
    031    public static final int USER = 0;
    032
    033    /** Command code {@value}. */
    034    public static final int PASS = 1;
    035
    036    /** Command code {@value}. */
    037    public static final int ACCT = 2;
    038
    039    /** Command code {@value}. */
    040    public static final int CWD = 3;
    041
    042    /** Command code {@value}. */
    043    public static final int CDUP = 4;
    044
    045    /** Command code {@value}. */
    046    public static final int SMNT = 5;
    047
    048    /** Command code {@value}. */
    049    public static final int REIN = 6;
    050
    051    /** Command code {@value}. */
    052    public static final int QUIT = 7;
    053
    054    /** Command code {@value}. */
    055    public static final int PORT = 8;
    056
    057    /** Command code {@value}. */
    058    public static final int PASV = 9;
    059
    060    /** Command code {@value}. */
    061    public static final int TYPE = 10;
    062
    063    /** Command code {@value}. */
    064    public static final int STRU = 11;
    065
    066    /** Command code {@value}. */
    067    public static final int MODE = 12;
    068
    069    /** Command code {@value}. */
    070    public static final int RETR = 13;
    071
    072    /** Command code {@value}. */
    073    public static final int STOR = 14;
    074
    075    /** Command code {@value}. */
    076
    077    /** Command code {@value}. */
    078    public static final int STOU = 15;
    079
    080    /** Command code {@value}. */
    081    public static final int APPE = 16;
    082
    083    /** Command code {@value}. */
    084
    085    /** Command code {@value}. */
    086    public static final int ALLO = 17;
    087
    088    /** Command code {@value}. */
    089    public static final int REST = 18;
    090
    091    /** Command code {@value}. */
    092    public static final int RNFR = 19;
    093
    094    /** Command code {@value}. */
    095    public static final int RNTO = 20;
    096
    097    /** Command code {@value}. */
    098    public static final int ABOR = 21;
    099
    100    /** Command code {@value}. */
    101    public static final int DELE = 22;
    102
    103    /** Command code {@value}. */
    104    public static final int RMD = 23;
    105
    106    /** Command code {@value}. */
    107    public static final int MKD = 24;
    108
    109    /** Command code {@value}. */
    110    public static final int PWD = 25;
    111
    112    /** Command code {@value}. */
    113    public static final int LIST = 26;
    114
    115    /** Command code {@value}. */
    116    public static final int NLST = 27;
    117
    118    /** Command code {@value}. */
    119    public static final int SITE = 28;
    120
    121    /** Command code {@value}. */
    122    public static final int SYST = 29;
    123
    124    /** Command code {@value}. */
    125    public static final int STAT = 30;
    126
    127    /** Command code {@value}. */
    128
    129    /** Command code {@value}. */
    130    public static final int HELP = 31;
    131
    132    /** Command code {@value}. */
    133    public static final int NOOP = 32;
    134
    135    /**
    136     * Command code {@value}.
    137     *
    138     * @since 2.0
    139     */
    140    public static final int MDTM = 33;
    141
    142    /**
    143     * Command code {@value}.
    144     *
    145     * @since 2.2
    146     */
    147    public static final int FEAT = 34;
    148
    149    /**
    150     * Command code {@value}.
    151     *
    152     * @since 2.0
    153     */
    154    public static final int MFMT = 35;
    155
    156    /**
    157     * Command code {@value}.
    158     *
    159     * @since 2.0
    160     */
    161    public static final int EPSV = 36;
    162
    163    /**
    164     * Command code {@value}.
    165     *
    166     * @since 2.0
    167     */
    168    public static final int EPRT = 37;
    169
    170    /**
    171     * Machine parseable list for a directory.
    172     *
    173     * @since 3.0
    174     */
    175    public static final int MLSD = 38;
    176
    177    /**
    178     * Machine parseable list for a single file.
    179     *
    180     * @since 3.0
    181     */
    182    public static final int MLST = 39;
    183
    184    // Must agree with final entry above; used to check array size
    185    private static final int LAST = MLST;
    186
    187    /** Alias for {@value}. */
    188    public static final int USERNAME = USER;
    189
    190    /** Alias for {@value}. */
    191    public static final int PASSWORD = PASS;
    192
    193    /** Alias for {@value}. */
    194    public static final int ACCOUNT = ACCT;
    195
    196    /** Alias for {@value}. */
    197    public static final int CHANGE_WORKING_DIRECTORY = CWD;
    198
    199    /** Alias for {@value}. */
    200    public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
    201
    202    /** Alias for {@value}. */
    203    public static final int STRUCTURE_MOUNT = SMNT;
    204
    205    /** Alias for {@value}. */
    206    public static final int REINITIALIZE = REIN;
    207
    208    /** Alias for {@value}. */
    209    public static final int LOGOUT = QUIT;
    210
    211    /** Alias for {@value}. */
    212    public static final int DATA_PORT = PORT;
    213
    214    /** Alias for {@value}. */
    215    public static final int PASSIVE = PASV;
    216
    217    /** Alias for {@value}. */
    218    public static final int REPRESENTATION_TYPE = TYPE;
    219
    220    /** Alias for {@value}. */
    221    public static final int FILE_STRUCTURE = STRU;
    222
    223    /** Alias for {@value}. */
    224    public static final int TRANSFER_MODE = MODE;
    225
    226    /** Alias for {@value}. */
    227    public static final int RETRIEVE = RETR;
    228
    229    /** Alias for {@value}. */
    230    public static final int STORE = STOR;
    231
    232    /** Alias for {@value}. */
    233    public static final int STORE_UNIQUE = STOU;
    234
    235    /** Alias for {@value}. */
    236    public static final int APPEND = APPE;
    237
    238    /** Alias for {@value}. */
    239    public static final int ALLOCATE = ALLO;
    240
    241    /** Alias for {@value}. */
    242    public static final int RESTART = REST;
    243
    244    /** Alias for {@value}. */
    245    public static final int RENAME_FROM = RNFR;
    246
    247    /** Alias for {@value}. */
    248    public static final int RENAME_TO = RNTO;
    249
    250    /** Alias for {@value}. */
    251    public static final int ABORT = ABOR;
    252
    253    /** Alias for {@value}. */
    254    public static final int DELETE = DELE;
    255
    256    /** Alias for {@value}. */
    257    public static final int REMOVE_DIRECTORY = RMD;
    258
    259    /** Alias for {@value}. */
    260    public static final int MAKE_DIRECTORY = MKD;
    261
    262    /** Alias for {@value}. */
    263    public static final int PRINT_WORKING_DIRECTORY = PWD;
    264
    265    // public static final int LIST = LIST;
    266
    267    /** Alias for {@value}. */
    268    public static final int NAME_LIST = NLST;
    269
    270    /** Alias for {@value}. */
    271    public static final int SITE_PARAMETERS = SITE;
    272
    273    /** Alias for {@value}. */
    274    public static final int SYSTEM = SYST;
    275
    276    /** Alias for {@value}. */
    277    public static final int STATUS = STAT;
    278
    279    // public static final int HELP = HELP;
    280    // public static final int NOOP = NOOP;
    281
    282    /**
    283     * Alias for {@value}.
    284     * @since 2.0
    285     */
    286    public static final int MOD_TIME = MDTM;
    287
    288    /**
    289     * Alias for {@value}.
    290     * @since 2.2
    291     */
    292    public static final int FEATURES = FEAT;
    293
    294    /**
    295     * Alias for {@value}.
    296     * @since 2.2
    297     */
    298    public static final int GET_MOD_TIME = MDTM;
    299
    300    /**
    301     * Alias for {@value}.
    302     * @since 2.2
    303     */
    304    public static final int SET_MOD_TIME = MFMT;
    305
    306    private static final String[] COMMANDS = { "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT", "PASV", "TYPE", "STRU", "MODE", "RETR",
    307            "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP",
    308            "MDTM", "FEAT", "MFMT", "EPSV", "EPRT", "MLSD", "MLST" };
    309
    310    /**
    311     * Default access needed for Unit test.
    312     */
    313    static void checkArray() {
    314        final int expectedLength = LAST + 1;
    315        if (COMMANDS.length != expectedLength) {
    316            throw new IllegalStateException("Incorrect COMMANDS array. Should have length " + expectedLength + " found " + COMMANDS.length);
    317        }
    318    }
    319
    320    /**
    321     * Gets the FTP protocol command string corresponding to a specified command code.
    322     *
    323     * @param command The command code.
    324     * @return The FTP protcol command string corresponding to a specified command code.
    325     */
    326    public static String getCommand(final int command) {
    327        return COMMANDS[command];
    328    }
    329
    330    /** Cannot be instantiated. */
    331    private FTPCommand() {
    332    }
    333}