Class FtpResponse


  • public class FtpResponse
    extends Object
    Represents an FTP command response.
    Version:
    $Id: $
    Author:
    DJ Gregor
    • Constructor Detail

      • FtpResponse

        public FtpResponse​(int code,
                           String[] response)
        Creates an FTP response with given status code and response string.
        Parameters:
        code - numeric status code
        response - response detail message (one line per array element)
    • Method Detail

      • getCode

        public int getCode()
        Gets the numeric response code.
        Returns:
        numeric status code
      • setCode

        public void setCode​(int code)
        Sets the numeric response code.
        Parameters:
        code - numeric status code
      • getResponse

        public String[] getResponse()
        Gets the response string array.
        Returns:
        response detail message (one line per array element)
      • setResponse

        public void setResponse​(String[] response)
        Sets the response string array.
        Parameters:
        response - response detail message (one line per array element)
      • responseContains

        public boolean responseContains​(String contain)
        Search for a text string in each line of the response result. Note that each line is tested individually.
        Parameters:
        contain - text to search for (using String.contains(contain))
        Returns:
        true if the search string is found, false otherwise
      • toString

        public String toString()
        Converts FTP response to string.
        Overrides:
        toString in class Object
        Returns:
        FTP response as would be sent over FTP
      • isCodeValid

        public boolean isCodeValid()
        Does this response have a valid code?
        Returns:
        True if the response code is between 100 and 599, false otherwise.
      • isSuccess

        public boolean isSuccess()
        Is this response a successful message?
        Returns:
        True if the response code is between 200 and 299, false otherwise.
      • isIntermediate

        public boolean isIntermediate()
        Is this response an intermediate message?
        Returns:
        True if the response code is between 300 and 399, false otherwise.
      • sendCommand

        public static void sendCommand​(Socket socket,
                                       String command)
                                throws IOException
        Helper method to send commands to the remote server.
        Parameters:
        socket - connection to the server
        command - command to send, without trailing EOL (CRLF, \r\n).
        Throws:
        IOException - if we can't write() to the OutputStream for the Socket