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