org.finj
Class FTPResponse

java.lang.Object
  extended by org.finj.FTPResponse

public class FTPResponse
extends java.lang.Object

This class contains constants and methods that simplify handling and internationalization of FTP server replies. Codes according to RFC959-4.2 http://www.ietf.org/rfc/rfc0959.txt (October 1995).

Copyright (C) 2000-2008 Javier Iglesias.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Version:
$Id: FTPResponse.java 57 2009-07-21 22:59:27Z jiglesias $
Author:
Javier Iglesias -- jiglesias@users.sourceforge.net

Field Summary
static int BAD_COMMAND_SEQUENCE_CODE
          Bad sequence of commands.
static int CAN_T_OPEN_DATA_CONNECTION_CODE
          Can't open data connection.
static int COMMAND_NOT_IMPLEMENTED_CODE
          Command not implemented.
static int COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE
          Command not implemented for that parameter.
static int CONTROL_CONNECTION_CLOSED_CODE
          Service closing control connection.
static int CONTROL_CONNECTION_OPENED_CODE
          Service ready for new user.
static int DATA_CONNECTION_ABORTED_CODE
          Connection closed; transfer aborted.
static int DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE
          File status okay; about to open data connection.
static int DATA_CONNECTION_ALREADY_OPENED_CODE
          Data Connection already open; transfer starting.
static int DATA_CONNECTION_CLOSED_CODE
          Closing data connection.
static int DATA_CONNECTION_OPENED_CODE
          Data connection open; no transfer in progress.
static int DIRECTORY_STATUS_CODE
          Directory status
static int ENTERING_PASSIVE_MODE_CODE
          Entering Passive Mode (h1,h2,h3,h4,p1,p2).
static int EXCEEDED_STORAGE_ALLOCATION_CODE
          Requested file action aborted.
static int FILE_STATUS_CODE
          File status.
static int FINE_NAME_NOT_ALLOWED_CODE
          Requested action not taken.
static int HELP_MESSAGE_CODE
          Help message.
static int NEED_ACCOUNT_FOR_LOGIN_CODE
          Need account for login.
static int NEED_ACCOUNT_FOR_STORING_FILES_CODE
          Need account for storing files.
static int NOT_LOGGED_IN_CODE
          Not logged in.
static int PAGE_TYPE_UNKNOWN_CODE
          Requested action aborted: page type unknown.
static int PATHNAME_CREATED_CODE
          "PATHNAME" created.
static int PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE
          Syntax error, command unrecognized.
static int PERMANENTLY_UNAVAILABLE_FILE_CODE
          Requested action not taken.
static int POSITIVE_COMPLETION_RESPONSE_CODE
          Command okay.
static int REQUESTED_FILE_ACTION_OK_CODE
          Requested file action okay, completed.
static int REQUESTED_FILE_ACTION_PENDING_CODE
          Requested file action pending further information.
static int RESTART_MARKER_RESPONSE_CODE
          Restart marker response.
static int SERVICE_NOT_AVAILABLE_CODE
          Service not available, closing control connection.
static int SUPERFLOUS_COMMAND_CODE
          Command not implemented, superfluous at this site.
static int SYNTAX_ERROR_IN_ARGUMENTS_CODE
          Syntax error n parameters or arguments.
static int SYSTEM_STATUS_OR_HELP_RESPONSE_CODE
          System status, or system help response.
static int SYSTEM_TYPE_NAME_CODE
          NAME system type.
static int TRANSIENT_INSUFFICIENT_STORAGE_SPACE_CODE
          Requested action not taken.
static int TRANSIENT_LOCAL_PROCESSING_ERROR_CODE
          Requested action aborted: local error in processing.
static int TRANSIENT_UNAVAILABLE_FILE_CODE
          Requested file action not taken.
static int USER_LOGGED_IN_CODE
          User logged in, proceed.
static int USERNAME_OK_NEED_PASSWORD_CODE
          User name okay, need password.
static int WILL_BE_READY_IN_MINUTES_CODE
          Service ready in nnn minutes.
 
Constructor Summary
FTPResponse(int code, java.lang.String text, java.lang.String[] multi, java.util.Locale locale)
          Initializes the current instance with the info provided.
FTPResponse(java.lang.String response)
          Constructs a new instance of this class that will use FTPConstants.DEFAULT_LOCALE as default locale.
FTPResponse(java.lang.String response, java.util.Locale locale)
          Constructs a new instance of this class that will use locale as message language.
FTPResponse(java.lang.String response, java.lang.String[] multiline)
          Constructs a new instance of this class that will use FTPConstants.DEFAULT_LOCALE as default locale, and will store a multiline answer.
FTPResponse(java.lang.String response, java.lang.String[] multiline, java.util.Locale locale)
          Constructs a new instance of this class that will use locale as message language.
 
Method Summary
static boolean closesMultilineResponse(java.lang.String response, int code)
          Tests a line of a response to know if it closes a multiline answer.
 int getCode()
          Returns the FTP code of this response.
 java.lang.String getMessage()
          Returns a localized version of the message corresponding to the original one's code.
protected  java.lang.String getMessageFromCode(int code)
          Returns the message that corresponds to the code given as parameter.
 java.lang.String[] getMultilineText()
          Returns the multiline answer received with this response.
 java.lang.String getOriginalMessage()
          Returns the original message received from the FTP server and passed at construction time.
 boolean isMultiline()
          Returns true if this response anounces a multi line response, e.g., STAT command.
static boolean opensMultilineResponse(java.lang.String response)
          Tests the first line of a response to know if it opens a multiline answer.
static int parseCode(java.lang.String response)
          Returns the code contained in the response passed as parameter.
static java.lang.String parseOriginalMessage(java.lang.String response)
          Returns the message contained in the response passed as parameter.
 java.lang.String[] parseServerPassivePort()
          Returns the host passive port parsed from the original text of response.
 java.lang.String parseWorkingDirectory()
          This command causes the name of the current working directory to be returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESTART_MARKER_RESPONSE_CODE

public static final int RESTART_MARKER_RESPONSE_CODE
Restart marker response. In this case, the text is exact and not left to the particular implementation; it must read : MARK yyyy = mmmm Where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note the spaces between markers and '=`).

Since:
v1.0
See Also:
"RFC959-4:2:'110'", Constant Field Values

WILL_BE_READY_IN_MINUTES_CODE

public static final int WILL_BE_READY_IN_MINUTES_CODE
Service ready in nnn minutes.

Since:
v1.0
See Also:
"RFC959-4:2:'120'", Constant Field Values

DATA_CONNECTION_ALREADY_OPENED_CODE

public static final int DATA_CONNECTION_ALREADY_OPENED_CODE
Data Connection already open; transfer starting.

Since:
v1.0
See Also:
"RFC959-4:2:'125'", Constant Field Values

DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE

public static final int DATA_CONNECTION_ABOUT_TO_BE_OPENED_CODE
File status okay; about to open data connection.

Since:
v1.0
See Also:
"RFC959-4:2:'150'", Constant Field Values

POSITIVE_COMPLETION_RESPONSE_CODE

public static final int POSITIVE_COMPLETION_RESPONSE_CODE
Command okay.

Since:
v1.0
See Also:
"RFC959-4:2:'200'", Constant Field Values

SUPERFLOUS_COMMAND_CODE

public static final int SUPERFLOUS_COMMAND_CODE
Command not implemented, superfluous at this site.

Since:
v1.0
See Also:
"RFC959-4:2:'202'", Constant Field Values

SYSTEM_STATUS_OR_HELP_RESPONSE_CODE

public static final int SYSTEM_STATUS_OR_HELP_RESPONSE_CODE
System status, or system help response.

Since:
v1.0
See Also:
"RFC959-4:2:'211'", Constant Field Values

DIRECTORY_STATUS_CODE

public static final int DIRECTORY_STATUS_CODE
Directory status

Since:
v1.0
See Also:
"RFC959-4:2:'212'", Constant Field Values

FILE_STATUS_CODE

public static final int FILE_STATUS_CODE
File status.

Since:
v1.0
See Also:
"RFC959-4:2:'213'", Constant Field Values

HELP_MESSAGE_CODE

public static final int HELP_MESSAGE_CODE
Help message. On how to use the server or the meaning of a particular non-standard command. This response is useful only to the human user.

Since:
v1.0
See Also:
"RFC959-4:2:'214'", Constant Field Values

SYSTEM_TYPE_NAME_CODE

public static final int SYSTEM_TYPE_NAME_CODE
NAME system type. Where NAME is an official system name from the list in the Assigned Numbers document.

Since:
v1.0
See Also:
"RFC959-4:2:'215'", "RFC1700", Constant Field Values

CONTROL_CONNECTION_OPENED_CODE

public static final int CONTROL_CONNECTION_OPENED_CODE
Service ready for new user.

Since:
v1.0
See Also:
"RFC959-4:2:'220'", Constant Field Values

CONTROL_CONNECTION_CLOSED_CODE

public static final int CONTROL_CONNECTION_CLOSED_CODE
Service closing control connection. Logged out if appropriate.

Since:
v1.0
See Also:
"RFC959-4:2:'221'", Constant Field Values

DATA_CONNECTION_OPENED_CODE

public static final int DATA_CONNECTION_OPENED_CODE
Data connection open; no transfer in progress.

Since:
v1.0
See Also:
"RFC959-4:2:'225'", Constant Field Values

DATA_CONNECTION_CLOSED_CODE

public static final int DATA_CONNECTION_CLOSED_CODE
Closing data connection. Requested file action successful (e.g., file transfer or file abort).

Since:
v1.0
See Also:
"RFC959-4:2:'226'", Constant Field Values

ENTERING_PASSIVE_MODE_CODE

public static final int ENTERING_PASSIVE_MODE_CODE
Entering Passive Mode (h1,h2,h3,h4,p1,p2).

Since:
v1.0
See Also:
"RFC959-4:2:'227'", Constant Field Values

USER_LOGGED_IN_CODE

public static final int USER_LOGGED_IN_CODE
User logged in, proceed.

Since:
v1.0
See Also:
"RFC959-4:2:'230'", Constant Field Values

REQUESTED_FILE_ACTION_OK_CODE

public static final int REQUESTED_FILE_ACTION_OK_CODE
Requested file action okay, completed.

Since:
v1.0
See Also:
"RFC959-4:2:'250'", Constant Field Values

PATHNAME_CREATED_CODE

public static final int PATHNAME_CREATED_CODE
"PATHNAME" created.

Since:
v1.0
See Also:
"RFC959-4:2:'257'", Constant Field Values

USERNAME_OK_NEED_PASSWORD_CODE

public static final int USERNAME_OK_NEED_PASSWORD_CODE
User name okay, need password.

Since:
v1.0
See Also:
"RFC959-4:2;'331'", Constant Field Values

NEED_ACCOUNT_FOR_LOGIN_CODE

public static final int NEED_ACCOUNT_FOR_LOGIN_CODE
Need account for login.

Since:
v1.0
See Also:
"RFC959-4:2:'332'", Constant Field Values

REQUESTED_FILE_ACTION_PENDING_CODE

public static final int REQUESTED_FILE_ACTION_PENDING_CODE
Requested file action pending further information.

Since:
v1.0
See Also:
"RFC959-4:2:'350'", Constant Field Values

SERVICE_NOT_AVAILABLE_CODE

public static final int SERVICE_NOT_AVAILABLE_CODE
Service not available, closing control connection. This may be a response to any command if the service knows it must shut down.

Since:
v1.0
See Also:
"RFC959-4:2:'421'", Constant Field Values

CAN_T_OPEN_DATA_CONNECTION_CODE

public static final int CAN_T_OPEN_DATA_CONNECTION_CODE
Can't open data connection.

Since:
v1.0
See Also:
"RFC959-4:2:'425'", Constant Field Values

DATA_CONNECTION_ABORTED_CODE

public static final int DATA_CONNECTION_ABORTED_CODE
Connection closed; transfer aborted.

Since:
v1.0
See Also:
"RFC959-4:2:'426'", Constant Field Values

TRANSIENT_UNAVAILABLE_FILE_CODE

public static final int TRANSIENT_UNAVAILABLE_FILE_CODE
Requested file action not taken. File unavailable (e.g., file busy).

Since:
v1.0
See Also:
"RFC959-4:2:'450'", Constant Field Values

TRANSIENT_LOCAL_PROCESSING_ERROR_CODE

public static final int TRANSIENT_LOCAL_PROCESSING_ERROR_CODE
Requested action aborted: local error in processing.

Since:
v1.0
See Also:
"RFC959-4:2:'451'", Constant Field Values

TRANSIENT_INSUFFICIENT_STORAGE_SPACE_CODE

public static final int TRANSIENT_INSUFFICIENT_STORAGE_SPACE_CODE
Requested action not taken. Insufficient storage space in system.

Since:
v1.0
See Also:
"RFC959-4:2:'452'", Constant Field Values

PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE

public static final int PERMANENT_NEGATIVE_COMPLETION_RESPONSE_CODE
Syntax error, command unrecognized. This may include errors such as command line too long.

Since:
v1.0
See Also:
"RFC959-4:2:'500'", Constant Field Values

SYNTAX_ERROR_IN_ARGUMENTS_CODE

public static final int SYNTAX_ERROR_IN_ARGUMENTS_CODE
Syntax error n parameters or arguments.

Since:
v1.0
See Also:
"RFC959-4:2:'501'", Constant Field Values

COMMAND_NOT_IMPLEMENTED_CODE

public static final int COMMAND_NOT_IMPLEMENTED_CODE
Command not implemented.

Since:
v1.0
See Also:
"RFC959-4:2:'502'", Constant Field Values

BAD_COMMAND_SEQUENCE_CODE

public static final int BAD_COMMAND_SEQUENCE_CODE
Bad sequence of commands.

Since:
v1.0
See Also:
"RFC959-4:2:'503'", Constant Field Values

COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE

public static final int COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER_CODE
Command not implemented for that parameter.

Since:
v1.0
See Also:
"RFC959-4:2:'504'", Constant Field Values

NOT_LOGGED_IN_CODE

public static final int NOT_LOGGED_IN_CODE
Not logged in.

Since:
v1.0
See Also:
"RFC959-4:2:'530'", Constant Field Values

NEED_ACCOUNT_FOR_STORING_FILES_CODE

public static final int NEED_ACCOUNT_FOR_STORING_FILES_CODE
Need account for storing files.

Since:
v1.0
See Also:
"RFC959-4:2:'532'", Constant Field Values

PERMANENTLY_UNAVAILABLE_FILE_CODE

public static final int PERMANENTLY_UNAVAILABLE_FILE_CODE
Requested action not taken. File unavailable (e.g., file not found, no access).

Since:
v1.0
See Also:
"RFC959-4:2:'550'", Constant Field Values

PAGE_TYPE_UNKNOWN_CODE

public static final int PAGE_TYPE_UNKNOWN_CODE
Requested action aborted: page type unknown.

Since:
v1.0
See Also:
"RFC959-4:2:'551'", Constant Field Values

EXCEEDED_STORAGE_ALLOCATION_CODE

public static final int EXCEEDED_STORAGE_ALLOCATION_CODE
Requested file action aborted. Exceed storage allocation (for current directory or dataset).

Since:
v1.0
See Also:
"RFC959-4:2:'552'", Constant Field Values

FINE_NAME_NOT_ALLOWED_CODE

public static final int FINE_NAME_NOT_ALLOWED_CODE
Requested action not taken. File name not allowed.

Since:
v1.0
See Also:
"RFC959-4:2:'553'", Constant Field Values
Constructor Detail

FTPResponse

public FTPResponse(java.lang.String response)
Constructs a new instance of this class that will use FTPConstants.DEFAULT_LOCALE as default locale.

Parameters:
response - original response message received on the control connection.
Since:
v1.0

FTPResponse

public FTPResponse(java.lang.String response,
                   java.lang.String[] multiline)
Constructs a new instance of this class that will use FTPConstants.DEFAULT_LOCALE as default locale, and will store a multiline answer.

Parameters:
response - original response message received on the control connection.
multiline - text received with this response.
Since:
v1.0

FTPResponse

public FTPResponse(java.lang.String response,
                   java.util.Locale locale)
            throws java.lang.IllegalArgumentException
Constructs a new instance of this class that will use locale as message language. If not available, messages for default language (Locale.US) will be used.

Parameters:
response - original response message received on the control connection.
locale - language to use for message.
Throws:
java.lang.IllegalArgumentException
Since:
v1.0

FTPResponse

public FTPResponse(java.lang.String response,
                   java.lang.String[] multiline,
                   java.util.Locale locale)
            throws java.lang.IllegalArgumentException
Constructs a new instance of this class that will use locale as message language. If not available, messages for default language (Locale.US) will be used.

Parameters:
response - original response message received on the control connection.
multiline - text received with this response.
locale - language to use for message.
Throws:
java.lang.IllegalArgumentException
Since:
v1.0

FTPResponse

public FTPResponse(int code,
                   java.lang.String text,
                   java.lang.String[] multi,
                   java.util.Locale locale)
Initializes the current instance with the info provided.

Parameters:
code - valid FTP code.
text - original message found in the response.
multi - multiline info received with this message.
locale - language to use for message.
Since:
v1.0
Method Detail

getCode

public int getCode()
Returns the FTP code of this response.

Returns:
FTP code
Since:
v1.0

getMessage

public java.lang.String getMessage()
Returns a localized version of the message corresponding to the original one's code. This will only work if a localized version of the messages are provided.

Returns:
code of the response sent by FTP server.
Since:
v1.0

getOriginalMessage

public java.lang.String getOriginalMessage()
Returns the original message received from the FTP server and passed at construction time.

Returns:
original message text.
Since:
v1.0

isMultiline

public boolean isMultiline()
Returns true if this response anounces a multi line response, e.g., STAT command.

Returns:
true if more lines are coming next the one used to construct this instance.
Since:
v1.0
See Also:
"RFC959-4:2"

getMultilineText

public java.lang.String[] getMultilineText()
Returns the multiline answer received with this response.

Returns:
multiline answer if exists, null else.
Since:
v1.0

getMessageFromCode

protected java.lang.String getMessageFromCode(int code)
Returns the message that corresponds to the code given as parameter.

Parameters:
code - one of the codes defined in this class.
Since:
v1.0

opensMultilineResponse

public static boolean opensMultilineResponse(java.lang.String response)
Tests the first line of a response to know if it opens a multiline answer.

Parameters:
response - FTP server response to interpret.
Since:
v1.0.2

closesMultilineResponse

public static boolean closesMultilineResponse(java.lang.String response,
                                              int code)
Tests a line of a response to know if it closes a multiline answer.

Parameters:
response - FTP server response to interpret.
Since:
v1.0.2

parseCode

public static int parseCode(java.lang.String response)
                     throws java.lang.IllegalArgumentException
Returns the code contained in the response passed as parameter. This code are in fact the 3 first characters of the response.

Parameters:
response - FTP server response to interpret.
Throws:
java.lang.IllegalArgumentException - when response's 3 first characters are not a valid three digit number
Since:
v1.0

parseOriginalMessage

public static java.lang.String parseOriginalMessage(java.lang.String response)
                                             throws java.lang.IllegalArgumentException
Returns the message contained in the response passed as parameter.

Parameters:
response - FTP server response to interpret.
Throws:
java.lang.IllegalArgumentException - when response isn't parsable.
Since:
v1.0

parseServerPassivePort

public java.lang.String[] parseServerPassivePort()
                                          throws FTPException
Returns the host passive port parsed from the original text of response. The author of this method is Syed Meerkasim.

Returns:
a java.lang.String[]
Throws:
FTPException - Response doesn't contain the required information
Since:
v1.0

parseWorkingDirectory

public java.lang.String parseWorkingDirectory()
This command causes the name of the current working directory to be returned.

Returns:
current working directory pathname.
Since:
v1.0
See Also:
"RFC959-4:1:3:'PWD'"


Copyright © 2009. All Rights Reserved.