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   * <p>
28   * <p>
29   * @deprecated use {@link FTPCmd} instead
30   */
31  @Deprecated
32  public final class FTPCommand
33  {
34  
35      public static final int USER = 0;
36      public static final int PASS = 1;
37      public static final int ACCT = 2;
38      public static final int CWD = 3;
39      public static final int CDUP = 4;
40      public static final int SMNT = 5;
41      public static final int REIN = 6;
42      public static final int QUIT = 7;
43      public static final int PORT = 8;
44      public static final int PASV = 9;
45      public static final int TYPE = 10;
46      public static final int STRU = 11;
47      public static final int MODE = 12;
48      public static final int RETR = 13;
49      public static final int STOR = 14;
50      public static final int STOU = 15;
51      public static final int APPE = 16;
52      public static final int ALLO = 17;
53      public static final int REST = 18;
54      public static final int RNFR = 19;
55      public static final int RNTO = 20;
56      public static final int ABOR = 21;
57      public static final int DELE = 22;
58      public static final int RMD = 23;
59      public static final int MKD = 24;
60      public static final int PWD = 25;
61      public static final int LIST = 26;
62      public static final int NLST = 27;
63      public static final int SITE = 28;
64      public static final int SYST = 29;
65      public static final int STAT = 30;
66      public static final int HELP = 31;
67      public static final int NOOP = 32;
68      /** @since 2.0 */
69      public static final int MDTM = 33;
70      /** @since 2.2 */
71      public static final int FEAT = 34;
72      /** @since 2.2 */
73      public static final int MFMT = 35;
74      /** @since 2.2 */
75      public static final int EPSV = 36;
76      /** @since 2.2 */
77      public static final int EPRT = 37;
78  
79      /**
80       *  Machine parseable list for a directory
81       * @since 3.0
82       */
83      public static final int MLSD = 38;
84  
85      /**
86       * Machine parseable list for a single file
87       * @since 3.0
88       */
89      public static final int MLST = 39;
90  
91      // Must agree with final entry above; used to check array size
92      private static final int LAST = MLST;
93  
94      public static final int USERNAME = USER;
95      public static final int PASSWORD = PASS;
96      public static final int ACCOUNT = ACCT;
97      public static final int CHANGE_WORKING_DIRECTORY = CWD;
98      public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
99      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 }