    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
    022 * the meaning of the codes, familiarity with RFC 959 is assumed.
    023 * The mnemonic constant names are transcriptions from the code descriptions
    024 * of RFC 959.  For those who think in terms of the actual FTP commands,
    025 * a set of constants such as {@link #USER  USER } are provided
    026 * where the constant name is the same as the FTP command.
    027 * <p>
    028 * <p>
    029 * @deprecated use {@link FTPCmd} instead
    030 */
    031@Deprecated
    032public final class FTPCommand
    033{
    034
    035    public static final int USER = 0;
    036    public static final int PASS = 1;
    037    public static final int ACCT = 2;
    038    public static final int CWD = 3;
    039    public static final int CDUP = 4;
    040    public static final int SMNT = 5;
    041    public static final int REIN = 6;
    042    public static final int QUIT = 7;
    043    public static final int PORT = 8;
    044    public static final int PASV = 9;
    045    public static final int TYPE = 10;
    046    public static final int STRU = 11;
    047    public static final int MODE = 12;
    048    public static final int RETR = 13;
    049    public static final int STOR = 14;
    050    public static final int STOU = 15;
    051    public static final int APPE = 16;
    052    public static final int ALLO = 17;
    053    public static final int REST = 18;
    054    public static final int RNFR = 19;
    055    public static final int RNTO = 20;
    056    public static final int ABOR = 21;
    057    public static final int DELE = 22;
    058    public static final int RMD = 23;
    059    public static final int MKD = 24;
    060    public static final int PWD = 25;
    061    public static final int LIST = 26;
    062    public static final int NLST = 27;
    063    public static final int SITE = 28;
    064    public static final int SYST = 29;
    065    public static final int STAT = 30;
    066    public static final int HELP = 31;
    067    public static final int NOOP = 32;
    068    /** @since 2.0 */
    069    public static final int MDTM = 33;
    070    /** @since 2.2 */
    071    public static final int FEAT = 34;
    072    /** @since 2.2 */
    073    public static final int MFMT = 35;
    074    /** @since 2.2 */
    075    public static final int EPSV = 36;
    076    /** @since 2.2 */
    077    public static final int EPRT = 37;
    078
    079    /**
    080     *  Machine parseable list for a directory
    081     * @since 3.0
    082     */
    083    public static final int MLSD = 38;
    084
    085    /**
    086     * Machine parseable list for a single file
    087     * @since 3.0
    088     */
    089    public static final int MLST = 39;
    090
    091    // Must agree with final entry above; used to check array size
    092    private static final int LAST = MLST;
    093
    094    public static final int USERNAME = USER;
    095    public static final int PASSWORD = PASS;
    096    public static final int ACCOUNT = ACCT;
    097    public static final int CHANGE_WORKING_DIRECTORY = CWD;
    098    public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
    099    public static final int STRUCTURE_MOUNT = SMNT;
    100    public static final int REINITIALIZE = REIN;
    101    public static final int LOGOUT = QUIT;
    102    public static final int DATA_PORT = PORT;
    103    public static final int PASSIVE = PASV;
    104    public static final int REPRESENTATION_TYPE = TYPE;
    105    public static final int FILE_STRUCTURE = STRU;
    106    public static final int TRANSFER_MODE = MODE;
    107    public static final int RETRIEVE = RETR;
    108    public static final int STORE = STOR;
    109    public static final int STORE_UNIQUE = STOU;
    110    public static final int APPEND = APPE;
    111    public static final int ALLOCATE = ALLO;
    112    public static final int RESTART = REST;
    113    public static final int RENAME_FROM = RNFR;
    114    public static final int RENAME_TO = RNTO;
    115    public static final int ABORT = ABOR;
    116    public static final int DELETE = DELE;
    117    public static final int REMOVE_DIRECTORY = RMD;
    118    public static final int MAKE_DIRECTORY = MKD;
    119    public static final int PRINT_WORKING_DIRECTORY = PWD;
    120    //  public static final int LIST = LIST;
    121    public static final int NAME_LIST = NLST;
    122    public static final int SITE_PARAMETERS = SITE;
    123    public static final int SYSTEM = SYST;
    124    public static final int STATUS = STAT;
    125    //public static final int HELP = HELP;
    126    //public static final int NOOP = NOOP;
    127
    128    /** @since 2.0 */
    129    public static final int MOD_TIME = MDTM;
    130
    131    /** @since 2.2 */
    132    public static final int FEATURES = FEAT;
    133    /** @since 2.2 */
    134    public static final int GET_MOD_TIME = MDTM;
    135    /** @since 2.2 */
    136    public static final int SET_MOD_TIME = MFMT;
    137
    138    // Cannot be instantiated
    139    private FTPCommand()
    140    {}
    141
    142    private static final String[] _commands = {
    143                                          "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT",
    144                                          "PASV", "TYPE", "STRU", "MODE", "RETR", "STOR", "STOU", "APPE", "ALLO",
    145                                          "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST",
    146                                          "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP", "MDTM", "FEAT", "MFMT",
    147                                          "EPSV", "EPRT", "MLSD", "MLST" };
    148
    149
    150
    151    // default access needed for Unit test
    152    static void checkArray(){
    153        int expectedLength = LAST+1;
    154        if (_commands.length != expectedLength) {
    155            throw new RuntimeException("Incorrect _commands array. Should have length "
    156                    +expectedLength+" found "+_commands.length);
    157        }
    158    }
    159
    160    /**
    161     * Retrieve the FTP protocol command string corresponding to a specified
    162     * command code.
    163     * <p>
    164     * @param command The command code.
    165     * @return The FTP protcol command string corresponding to a specified
    166     *         command code.
    167     */
    168    public static final String getCommand(int command)
    169    {
    170        return _commands[command];
    171    }
    172}