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 018package org.apache.commons.net.ftp; 019 020/*** 021 * FTPReply stores a set of constants for FTP reply 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. 025 * <p> 026 * TODO replace with an enum 027 ***/ 028 029public final class FTPReply 030{ 031 032 public static final int RESTART_MARKER = 110; 033 public static final int SERVICE_NOT_READY = 120; 034 public static final int DATA_CONNECTION_ALREADY_OPEN = 125; 035 public static final int FILE_STATUS_OK = 150; 036 public static final int COMMAND_OK = 200; 037 public static final int COMMAND_IS_SUPERFLUOUS = 202; 038 public static final int SYSTEM_STATUS = 211; 039 public static final int DIRECTORY_STATUS = 212; 040 public static final int FILE_STATUS = 213; 041 public static final int HELP_MESSAGE = 214; 042 public static final int NAME_SYSTEM_TYPE = 215; 043 public static final int SERVICE_READY = 220; 044 public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221; 045 public static final int DATA_CONNECTION_OPEN = 225; 046 public static final int CLOSING_DATA_CONNECTION = 226; 047 public static final int ENTERING_PASSIVE_MODE = 227; 048 /** @since 2.2 */ 049 public static final int ENTERING_EPSV_MODE = 229; 050 public static final int USER_LOGGED_IN = 230; 051 public static final int FILE_ACTION_OK = 250; 052 public static final int PATHNAME_CREATED = 257; 053 public static final int NEED_PASSWORD = 331; 054 public static final int NEED_ACCOUNT = 332; 055 public static final int FILE_ACTION_PENDING = 350; 056 public static final int SERVICE_NOT_AVAILABLE = 421; 057 public static final int CANNOT_OPEN_DATA_CONNECTION = 425; 058 public static final int TRANSFER_ABORTED = 426; 059 public static final int FILE_ACTION_NOT_TAKEN = 450; 060 public static final int ACTION_ABORTED = 451; 061 public static final int INSUFFICIENT_STORAGE = 452; 062 public static final int UNRECOGNIZED_COMMAND = 500; 063 public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501; 064 public static final int COMMAND_NOT_IMPLEMENTED = 502; 065 public static final int BAD_COMMAND_SEQUENCE = 503; 066 public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504; 067 public static final int NOT_LOGGED_IN = 530; 068 public static final int NEED_ACCOUNT_FOR_STORING_FILES = 532; 069 public static final int FILE_UNAVAILABLE = 550; 070 public static final int PAGE_TYPE_UNKNOWN = 551; 071 public static final int STORAGE_ALLOCATION_EXCEEDED = 552; 072 public static final int FILE_NAME_NOT_ALLOWED = 553; 073 074 // FTPS Reply Codes 075 076 /** @since 2.0 */ 077 public static final int SECURITY_DATA_EXCHANGE_COMPLETE = 234; 078 /** @since 2.0 */ 079 public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = 235; 080 /** @since 2.0 */ 081 public static final int SECURITY_MECHANISM_IS_OK = 334; 082 /** @since 2.0 */ 083 public static final int SECURITY_DATA_IS_ACCEPTABLE = 335; 084 /** @since 2.0 */ 085 public static final int UNAVAILABLE_RESOURCE = 431; 086 /** @since 2.2 */ 087 public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = 522; 088 /** @since 2.0 */ 089 public static final int DENIED_FOR_POLICY_REASONS = 533; 090 /** @since 2.0 */ 091 public static final int REQUEST_DENIED = 534; 092 /** @since 2.0 */ 093 public static final int FAILED_SECURITY_CHECK = 535; 094 /** @since 2.0 */ 095 public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = 536; 096 097 // IPv6 error codes 098 // Note this is also used as an FTPS error code reply 099 /** @since 2.2 */ 100 public static final int EXTENDED_PORT_FAILURE = 522; 101 102 // Cannot be instantiated 103 private FTPReply() 104 {} 105 106 /*** 107 * Determine if a reply code is a positive preliminary response. All 108 * codes beginning with a 1 are positive preliminary responses. 109 * Postitive preliminary responses are used to indicate tentative success. 110 * No further commands can be issued to the FTP server after a positive 111 * preliminary response until a follow up response is received from the 112 * server. 113 * 114 * @param reply The reply code to test. 115 * @return True if a reply code is a postive preliminary response, false 116 * if not. 117 ***/ 118 public static boolean isPositivePreliminary(int reply) 119 { 120 return (reply >= 100 && reply < 200); 121 } 122 123 /*** 124 * Determine if a reply code is a positive completion response. All 125 * codes beginning with a 2 are positive completion responses. 126 * The FTP server will send a positive completion response on the final 127 * successful completion of a command. 128 * 129 * @param reply The reply code to test. 130 * @return True if a reply code is a postive completion response, false 131 * if not. 132 ***/ 133 public static boolean isPositiveCompletion(int reply) 134 { 135 return (reply >= 200 && reply < 300); 136 } 137 138 /*** 139 * Determine if a reply code is a positive intermediate response. All 140 * codes beginning with a 3 are positive intermediate responses. 141 * The FTP server will send a positive intermediate response on the 142 * successful completion of one part of a multi-part sequence of 143 * commands. For example, after a successful USER command, a positive 144 * intermediate response will be sent to indicate that the server is 145 * ready for the PASS command. 146 * 147 * @param reply The reply code to test. 148 * @return True if a reply code is a postive intermediate response, false 149 * if not. 150 ***/ 151 public static boolean isPositiveIntermediate(int reply) 152 { 153 return (reply >= 300 && reply < 400); 154 } 155 156 /*** 157 * Determine if a reply code is a negative transient response. All 158 * codes beginning with a 4 are negative transient responses. 159 * The FTP server will send a negative transient response on the 160 * failure of a command that can be reattempted with success. 161 * 162 * @param reply The reply code to test. 163 * @return True if a reply code is a negative transient response, false 164 * if not. 165 ***/ 166 public static boolean isNegativeTransient(int reply) 167 { 168 return (reply >= 400 && reply < 500); 169 } 170 171 /*** 172 * Determine if a reply code is a negative permanent response. All 173 * codes beginning with a 5 are negative permanent responses. 174 * The FTP server will send a negative permanent response on the 175 * failure of a command that cannot be reattempted with success. 176 * 177 * @param reply The reply code to test. 178 * @return True if a reply code is a negative permanent response, false 179 * if not. 180 ***/ 181 public static boolean isNegativePermanent(int reply) 182 { 183 return (reply >= 500 && reply < 600); 184 } 185 186 /** 187 * Determine if a reply code is a protected response. 188 * @param reply The reply code to test. 189 * @return True if a reply code is a protected response, false 190 * if not. 191 * @since 3.0 192 */ 193 public static boolean isProtectedReplyCode(int reply) 194 { 195 // actually, only 3 protected reply codes are 196 // defined in RFC 2228: 631, 632 and 633. 197 return (reply >= 600 && reply < 700); 198 } 199 200 201}