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 the meaning of the codes, familiarity with RFC 959 is assumed. The mnemonic constant
22   * 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
23   * {@link #USER USER } are provided where the constant name is the same as the FTP command.
24   *
25   * @deprecated use {@link FTPCmd} instead
26   */
27  @Deprecated
28  public final class FTPCommand {
29  
30      /** Command code {@value}. */
31      public static final int USER = 0;
32  
33      /** Command code {@value}. */
34      public static final int PASS = 1;
35  
36      /** Command code {@value}. */
37      public static final int ACCT = 2;
38  
39      /** Command code {@value}. */
40      public static final int CWD = 3;
41  
42      /** Command code {@value}. */
43      public static final int CDUP = 4;
44  
45      /** Command code {@value}. */
46      public static final int SMNT = 5;
47  
48      /** Command code {@value}. */
49      public static final int REIN = 6;
50  
51      /** Command code {@value}. */
52      public static final int QUIT = 7;
53  
54      /** Command code {@value}. */
55      public static final int PORT = 8;
56  
57      /** Command code {@value}. */
58      public static final int PASV = 9;
59  
60      /** Command code {@value}. */
61      public static final int TYPE = 10;
62  
63      /** Command code {@value}. */
64      public static final int STRU = 11;
65  
66      /** Command code {@value}. */
67      public static final int MODE = 12;
68  
69      /** Command code {@value}. */
70      public static final int RETR = 13;
71  
72      /** Command code {@value}. */
73      public static final int STOR = 14;
74  
75      /** Command code {@value}. */
76  
77      /** Command code {@value}. */
78      public static final int STOU = 15;
79  
80      /** Command code {@value}. */
81      public static final int APPE = 16;
82  
83      /** Command code {@value}. */
84  
85      /** Command code {@value}. */
86      public static final int ALLO = 17;
87  
88      /** Command code {@value}. */
89      public static final int REST = 18;
90  
91      /** Command code {@value}. */
92      public static final int RNFR = 19;
93  
94      /** Command code {@value}. */
95      public static final int RNTO = 20;
96  
97      /** Command code {@value}. */
98      public static final int ABOR = 21;
99  
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      * Command code {@value}.
137      *
138      * @since 2.0
139      */
140     public static final int MDTM = 33;
141 
142     /**
143      * Command code {@value}.
144      *
145      * @since 2.2
146      */
147     public static final int FEAT = 34;
148 
149     /**
150      * Command code {@value}.
151      *
152      * @since 2.0
153      */
154     public static final int MFMT = 35;
155 
156     /**
157      * Command code {@value}.
158      *
159      * @since 2.0
160      */
161     public static final int EPSV = 36;
162 
163     /**
164      * Command code {@value}.
165      *
166      * @since 2.0
167      */
168     public static final int EPRT = 37;
169 
170     /**
171      * Machine parseable list for a directory.
172      *
173      * @since 3.0
174      */
175     public static final int MLSD = 38;
176 
177     /**
178      * Machine parseable list for a single file.
179      *
180      * @since 3.0
181      */
182     public static final int MLST = 39;
183 
184     // Must agree with final entry above; used to check array size
185     private static final int LAST = MLST;
186 
187     /** Alias for {@value}. */
188     public static final int USERNAME = USER;
189 
190     /** Alias for {@value}. */
191     public static final int PASSWORD = PASS;
192 
193     /** Alias for {@value}. */
194     public static final int ACCOUNT = ACCT;
195 
196     /** Alias for {@value}. */
197     public static final int CHANGE_WORKING_DIRECTORY = CWD;
198 
199     /** Alias for {@value}. */
200     public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
201 
202     /** Alias for {@value}. */
203     public static final int STRUCTURE_MOUNT = SMNT;
204 
205     /** Alias for {@value}. */
206     public static final int REINITIALIZE = REIN;
207 
208     /** Alias for {@value}. */
209     public static final int LOGOUT = QUIT;
210 
211     /** Alias for {@value}. */
212     public static final int DATA_PORT = PORT;
213 
214     /** Alias for {@value}. */
215     public static final int PASSIVE = PASV;
216 
217     /** Alias for {@value}. */
218     public static final int REPRESENTATION_TYPE = TYPE;
219 
220     /** Alias for {@value}. */
221     public static final int FILE_STRUCTURE = STRU;
222 
223     /** Alias for {@value}. */
224     public static final int TRANSFER_MODE = MODE;
225 
226     /** Alias for {@value}. */
227     public static final int RETRIEVE = RETR;
228 
229     /** Alias for {@value}. */
230     public static final int STORE = STOR;
231 
232     /** Alias for {@value}. */
233     public static final int STORE_UNIQUE = STOU;
234 
235     /** Alias for {@value}. */
236     public static final int APPEND = APPE;
237 
238     /** Alias for {@value}. */
239     public static final int ALLOCATE = ALLO;
240 
241     /** Alias for {@value}. */
242     public static final int RESTART = REST;
243 
244     /** Alias for {@value}. */
245     public static final int RENAME_FROM = RNFR;
246 
247     /** Alias for {@value}. */
248     public static final int RENAME_TO = RNTO;
249 
250     /** Alias for {@value}. */
251     public static final int ABORT = ABOR;
252 
253     /** Alias for {@value}. */
254     public static final int DELETE = DELE;
255 
256     /** Alias for {@value}. */
257     public static final int REMOVE_DIRECTORY = RMD;
258 
259     /** Alias for {@value}. */
260     public static final int MAKE_DIRECTORY = MKD;
261 
262     /** Alias for {@value}. */
263     public static final int PRINT_WORKING_DIRECTORY = PWD;
264 
265     // public static final int LIST = LIST;
266 
267     /** Alias for {@value}. */
268     public static final int NAME_LIST = NLST;
269 
270     /** Alias for {@value}. */
271     public static final int SITE_PARAMETERS = SITE;
272 
273     /** Alias for {@value}. */
274     public static final int SYSTEM = SYST;
275 
276     /** Alias for {@value}. */
277     public static final int STATUS = STAT;
278 
279     // public static final int HELP = HELP;
280     // public static final int NOOP = NOOP;
281 
282     /**
283      * Alias for {@value}.
284      * @since 2.0
285      */
286     public static final int MOD_TIME = MDTM;
287 
288     /**
289      * Alias for {@value}.
290      * @since 2.2
291      */
292     public static final int FEATURES = FEAT;
293 
294     /**
295      * Alias for {@value}.
296      * @since 2.2
297      */
298     public static final int GET_MOD_TIME = MDTM;
299 
300     /**
301      * Alias for {@value}.
302      * @since 2.2
303      */
304     public static final int SET_MOD_TIME = MFMT;
305 
306     private static final String[] COMMANDS = { "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT", "PASV", "TYPE", "STRU", "MODE", "RETR",
307             "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP",
308             "MDTM", "FEAT", "MFMT", "EPSV", "EPRT", "MLSD", "MLST" };
309 
310     /**
311      * Default access needed for Unit test.
312      */
313     static void checkArray() {
314         final int expectedLength = LAST + 1;
315         if (COMMANDS.length != expectedLength) {
316             throw new IllegalStateException("Incorrect COMMANDS array. Should have length " + expectedLength + " found " + COMMANDS.length);
317         }
318     }
319 
320     /**
321      * Retrieve the FTP protocol command string corresponding to a specified command code.
322      *
323      * @param command The command code.
324      * @return The FTP protcol command string corresponding to a specified command code.
325      */
326     public static String getCommand(final int command) {
327         return COMMANDS[command];
328     }
329 
330     /** Cannot be instantiated. */
331     private FTPCommand() {
332     }
333 }