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