    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 * 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    /**
    137     * Command code {@value}.
    138     *
    139     * @since 2.0
    140     */
    141    public static final int MDTM = 33;
    142
    143    /**
    144     * Command code {@value}.
    145     *
    146     * @since 2.2
    147     */
    148    public static final int FEAT = 34;
    149
    150    /**
    151     * Command code {@value}.
    152     *
    153     * @since 2.0
    154     */
    155    public static final int MFMT = 35;
    156
    157    /**
    158     * Command code {@value}.
    159     *
    160     * @since 2.0
    161     */
    162    public static final int EPSV = 36;
    163
    164    /**
    165     * Command code {@value}.
    166     *
    167     * @since 2.0
    168     */
    169    public static final int EPRT = 37;
    170
    171    /**
    172     * Machine parseable list for a directory.
    173     *
    174     * @since 3.0
    175     */
    176    public static final int MLSD = 38;
    177
    178    /**
    179     * Machine parseable list for a single file.
    180     *
    181     * @since 3.0
    182     */
    183    public static final int MLST = 39;
    184
    185    // Must agree with final entry above; used to check array size
    186    private static final int LAST = MLST;
    187
    188    /** Alias for {@value}. */
    189    public static final int USERNAME = USER;
    190
    191    /** Alias for {@value}. */
    192    public static final int PASSWORD = PASS;
    193
    194    /** Alias for {@value}. */
    195    public static final int ACCOUNT = ACCT;
    196
    197    /** Alias for {@value}. */
    198    public static final int CHANGE_WORKING_DIRECTORY = CWD;
    199
    200    /** Alias for {@value}. */
    201    public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
    202
    203    /** Alias for {@value}. */
    204    public static final int STRUCTURE_MOUNT = SMNT;
    205
    206    /** Alias for {@value}. */
    207    public static final int REINITIALIZE = REIN;
    208
    209    /** Alias for {@value}. */
    210    public static final int LOGOUT = QUIT;
    211
    212    /** Alias for {@value}. */
    213    public static final int DATA_PORT = PORT;
    214
    215    /** Alias for {@value}. */
    216    public static final int PASSIVE = PASV;
    217
    218    /** Alias for {@value}. */
    219    public static final int REPRESENTATION_TYPE = TYPE;
    220
    221    /** Alias for {@value}. */
    222    public static final int FILE_STRUCTURE = STRU;
    223
    224    /** Alias for {@value}. */
    225    public static final int TRANSFER_MODE = MODE;
    226
    227    /** Alias for {@value}. */
    228    public static final int RETRIEVE = RETR;
    229
    230    /** Alias for {@value}. */
    231    public static final int STORE = STOR;
    232
    233    /** Alias for {@value}. */
    234    public static final int STORE_UNIQUE = STOU;
    235
    236    /** Alias for {@value}. */
    237    public static final int APPEND = APPE;
    238
    239    /** Alias for {@value}. */
    240    public static final int ALLOCATE = ALLO;
    241
    242    /** Alias for {@value}. */
    243    public static final int RESTART = REST;
    244
    245    /** Alias for {@value}. */
    246    public static final int RENAME_FROM = RNFR;
    247
    248    /** Alias for {@value}. */
    249    public static final int RENAME_TO = RNTO;
    250
    251    /** Alias for {@value}. */
    252    public static final int ABORT = ABOR;
    253
    254    /** Alias for {@value}. */
    255    public static final int DELETE = DELE;
    256
    257    /** Alias for {@value}. */
    258    public static final int REMOVE_DIRECTORY = RMD;
    259
    260    /** Alias for {@value}. */
    261    public static final int MAKE_DIRECTORY = MKD;
    262
    263    /** Alias for {@value}. */
    264    public static final int PRINT_WORKING_DIRECTORY = PWD;
    265
    266    // public static final int LIST = LIST;
    267
    268    /** Alias for {@value}. */
    269    public static final int NAME_LIST = NLST;
    270
    271    /** Alias for {@value}. */
    272    public static final int SITE_PARAMETERS = SITE;
    273
    274    /** Alias for {@value}. */
    275    public static final int SYSTEM = SYST;
    276
    277    /** Alias for {@value}. */
    278    public static final int STATUS = STAT;
    279
    280    // public static final int HELP = HELP;
    281    // public static final int NOOP = NOOP;
    282
    283    /**
    284     * Alias for {@value}.
    285     * @since 2.0
    286     */
    287    public static final int MOD_TIME = MDTM;
    288
    289    /**
    290     * Alias for {@value}.
    291     * @since 2.2
    292     */
    293    public static final int FEATURES = FEAT;
    294
    295    /**
    296     * Alias for {@value}.
    297     * @since 2.2
    298     */
    299    public static final int GET_MOD_TIME = MDTM;
    300
    301    /**
    302     * Alias for {@value}.
    303     * @since 2.2
    304     */
    305    public static final int SET_MOD_TIME = MFMT;
    306
    307    private static final String[] COMMANDS = { "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT", "PASV", "TYPE", "STRU", "MODE", "RETR",
    308            "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP",
    309            "MDTM", "FEAT", "MFMT", "EPSV", "EPRT", "MLSD", "MLST" };
    310
    311    /**
    312     * Default access needed for Unit test.
    313     */
    314    static void checkArray() {
    315        final int expectedLength = LAST + 1;
    316        if (COMMANDS.length != expectedLength) {
    317            throw new IllegalStateException("Incorrect COMMANDS array. Should have length " + expectedLength + " found " + COMMANDS.length);
    318        }
    319    }
    320
    321    /**
    322     * Retrieve the FTP protocol command string corresponding to a specified command code.
    323     *
    324     * @param command The command code.
    325     * @return The FTP protcol command string corresponding to a specified command code.
    326     */
    327    public static String getCommand(final int command) {
    328        return COMMANDS[command];
    329    }
    330
    331    /** Cannot be instantiated. */
    332    private FTPCommand() {
    333    }
    334}