Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you tried like this?</p> <pre><code> StringBuilder response = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); do { response.append(br.readLine()); } while (br.ready()); </code></pre> <p>Whereas the <a href="http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html" rel="nofollow">BufferedReader</a>'s <a href="http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#ready%28%29" rel="nofollow">ready()</a> method:</p> <blockquote> <p>Tells whether this stream is ready to be read. A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready. <br/>Returns:<br/> True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.</p> </blockquote> <p>It is actually a <a href="http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html" rel="nofollow">Reader</a>'s <a href="http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html#ready%28%29" rel="nofollow">method</a>.</p> <p>UPDATE:</p> <p>As glglgl pointed out there are two types of responses in FTP:</p> <ul> <li>"single line" response (my term)</li> <li>multiline response (spec term) </li> </ul> <p>As I said in comment, fire up FIlleZilla, connect and observe the log (preferably comparing the commands in output with spec defintion) and you will see why the "single line" is quoted.</p> <p>On some FTP server implementations the above code may work, but it will surley not work on all implementations, since it does not implement the client part of the protocol correctly. This is the updated version:</p> <pre><code>String response; List&lt;String&gt; responseList = new ArrayList&lt;String&gt;(); boolean isMultilineStart = false, isMultilineEnd = false; String mlCode = null; do { responseList.add(br.readLine()); if (!isMultilineStart) { isMultilineStart = responseList.get(responseList.size()-1).matches("\\d\\d\\d-.*"); mlCode = responseList.get(responseList.size()-1).substring(0,3); } else { isMultilineEnd = responseList.get(responseList.size()-1).startsWith(mlCode+" "); } } while (br.ready() || (isMultilineStart &amp;&amp; !isMultilineEnd)); response = Arrays.deepToString(responseList.toArray()); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload