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     /**
137      * Command code {@value}.
138      *
139      * @since 2.0
140      */
141     public static final int MDTM = 33;
142 
143     /**
144      * Command code {@value}.
145      *
146      * @since 2.2
147      */
148     public static final int FEAT = 34;
149 
150     /**
151      * Command code {@value}.
152      *
153      * @since 2.0
154      */
155     public static final int MFMT = 35;
156 
157     /**
158      * Command code {@value}.
159      *
160      * @since 2.0
161      */
162     public static final int EPSV = 36;
163 
164     /**
165      * Command code {@value}.
166      *
167      * @since 2.0
168      */
169     public static final int EPRT = 37;
170 
171     /**
172      * Machine parseable list for a directory.
173      *
174      * @since 3.0
175      */
176     public static final int MLSD = 38;
177 
178     /**
179      * Machine parseable list for a single file.
180      *
181      * @since 3.0
182      */
183     public static final int MLST = 39;
184 
185     // Must agree with final entry above; used to check array size
186     private static final int LAST = MLST;
187 
188     /** Alias for {@value}. */
189     public static final int USERNAME = USER;
190 
191     /** Alias for {@value}. */
192     public static final int PASSWORD = PASS;
193 
194     /** Alias for {@value}. */
195     public static final int ACCOUNT = ACCT;
196 
197     /** Alias for {@value}. */
198     public static final int CHANGE_WORKING_DIRECTORY = CWD;
199 
200     /** Alias for {@value}. */
201     public static final int CHANGE_TO_PARENT_DIRECTORY = CDUP;
202 
203     /** Alias for {@value}. */
204     public static final int STRUCTURE_MOUNT = SMNT;
205 
206     /** Alias for {@value}. */
207     public static final int REINITIALIZE = REIN;
208 
209     /** Alias for {@value}. */
210     public static final int LOGOUT = QUIT;
211 
212     /** Alias for {@value}. */
213     public static final int DATA_PORT = PORT;
214 
215     /** Alias for {@value}. */
216     public static final int PASSIVE = PASV;
217 
218     /** Alias for {@value}. */
219     public static final int REPRESENTATION_TYPE = TYPE;
220 
221     /** Alias for {@value}. */
222     public static final int FILE_STRUCTURE = STRU;
223 
224     /** Alias for {@value}. */
225     public static final int TRANSFER_MODE = MODE;
226 
227     /** Alias for {@value}. */
228     public static final int RETRIEVE = RETR;
229 
230     /** Alias for {@value}. */
231     public static final int STORE = STOR;
232 
233     /** Alias for {@value}. */
234     public static final int STORE_UNIQUE = STOU;
235 
236     /** Alias for {@value}. */
237     public static final int APPEND = APPE;
238 
239     /** Alias for {@value}. */
240     public static final int ALLOCATE = ALLO;
241 
242     /** Alias for {@value}. */
243     public static final int RESTART = REST;
244 
245     /** Alias for {@value}. */
246     public static final int RENAME_FROM = RNFR;
247 
248     /** Alias for {@value}. */
249     public static final int RENAME_TO = RNTO;
250 
251     /** Alias for {@value}. */
252     public static final int ABORT = ABOR;
253 
254     /** Alias for {@value}. */
255     public static final int DELETE = DELE;
256 
257     /** Alias for {@value}. */
258     public static final int REMOVE_DIRECTORY = RMD;
259 
260     /** Alias for {@value}. */
261     public static final int MAKE_DIRECTORY = MKD;
262 
263     /** Alias for {@value}. */
264     public static final int PRINT_WORKING_DIRECTORY = PWD;
265 
266     // public static final int LIST = LIST;
267 
268     /** Alias for {@value}. */
269     public static final int NAME_LIST = NLST;
270 
271     /** Alias for {@value}. */
272     public static final int SITE_PARAMETERS = SITE;
273 
274     /** Alias for {@value}. */
275     public static final int SYSTEM = SYST;
276 
277     /** Alias for {@value}. */
278     public static final int STATUS = STAT;
279 
280     // public static final int HELP = HELP;
281     // public static final int NOOP = NOOP;
282 
283     /**
284      * Alias for {@value}.
285      * @since 2.0
286      */
287     public static final int MOD_TIME = MDTM;
288 
289     /**
290      * Alias for {@value}.
291      * @since 2.2
292      */
293     public static final int FEATURES = FEAT;
294 
295     /**
296      * Alias for {@value}.
297      * @since 2.2
298      */
299     public static final int GET_MOD_TIME = MDTM;
300 
301     /**
302      * Alias for {@value}.
303      * @since 2.2
304      */
305     public static final int SET_MOD_TIME = MFMT;
306 
307     private static final String[] COMMANDS = { "USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT", "PASV", "TYPE", "STRU", "MODE", "RETR",
308             "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST", "STAT", "HELP", "NOOP",
309             "MDTM", "FEAT", "MFMT", "EPSV", "EPRT", "MLSD", "MLST" };
310 
311     /**
312      * Default access needed for Unit test.
313      */
314     static void checkArray() {
315         final int expectedLength = LAST + 1;
316         if (COMMANDS.length != expectedLength) {
317             throw new IllegalStateException("Incorrect COMMANDS array. Should have length " + expectedLength + " found " + COMMANDS.length);
318         }
319     }
320 
321     /**
322      * Retrieve the FTP protocol command string corresponding to a specified command code.
323      *
324      * @param command The command code.
325      * @return The FTP protcol command string corresponding to a specified command code.
326      */
327     public static String getCommand(final int command) {
328         return COMMANDS[command];
329     }
330 
331     /** Cannot be instantiated. */
332     private FTPCommand() {
333     }
334 }