View Javadoc
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  
18  package org.apache.commons.net.ftp;
19  
20  /**
21   * FTPCommand stores a set of constants for FTP command codes.  To interpret
22   * the meaning of the codes, familiarity with RFC 959 is assumed.
23   * The mnemonic constant names are transcriptions from the code descriptions
24   * of RFC 959.  For those who think in terms of the actual FTP commands,
25   * a set of constants such as {@link #USER  USER } are provided
26   * where the constant name is the same as the FTP command.
27   *
28   * @deprecated use {@link FTPCmd} instead
29   */
30  @Deprecated
31  public final class FTPCommand
32  {
33  
34      public static final int USER = 0;
35      public static final int PASS = 1;
36      public static final int ACCT = 2;
37      public static final int CWD = 3;
38      public static final int CDUP = 4;
39      public static final int SMNT = 5;
40      public static final int REIN = 6;
41      public static final int QUIT = 7;
42      public static final int PORT = 8;
43      public static final int PASV = 9;
44      public static final int TYPE = 10;
45      public static final int STRU = 11;
46      public static final int MODE = 12;
47      public static final int RETR = 13;
48      public static final int STOR = 14;
49      public static final int STOU = 15;
50      public static final int APPE = 16;
51      public static final int ALLO = 17;
52      public static final int REST = 18;
53      public static final int RNFR = 19;
54      public static final int RNTO = 20;
55      public static final int ABOR = 21;
56      public static final int DELE = 22;
57      public static final int RMD = 23;
58      public static final int MKD = 24;
59      public static final int PWD = 25;
60      public static final int LIST = 26;
61      public static final int NLST = 27;
62      public static final int SITE = 28;
63      public static final int SYST = 29;
64      public static final int STAT = 30;
65      public static final int HELP = 31;
66      public static final int NOOP = 32;
67      /** @since 2.0 */
68      public static final int MDTM = 33;
69      /** @since 2.2 */
70      public static final int FEAT = 34;
71      /** @since 2.2 */
72      public static final int MFMT = 35;
73      /** @since 2.2 */
74      public static final int EPSV = 36;
75      /** @since 2.2 */
76      public static final int EPRT = 37;
77  
78      /**
79       *  Machine parseable list for a directory
80       * @since 3.0
81       */
82      public static final int MLSD = 38;
83  
84      /**
85       * Machine parseable list for a single file
86       * @since 3.0
87       */
88      public static final int MLST = 39;
89  
90      // Must agree with final entry above; used to check array size
91      private static final int LAST = MLST;
92  
93      public static final int USERNAME = USER;
94      public static final int PASSWORD = PASS;
95      public static final int ACCOUNT = ACCT;
96      public static final int CHANGE_WORKING_DIRECTORY = CWD;
97      public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
98      public static final int STRUCTURE_MOUNT = SMNT;
99      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 }