title: How to know the end of FTP Welcome message
body: <p>My problem is that I'm creating a FTP client, and so far its working flawlessly besides one minor detail, that keeps bugging me.
  I need to know how many lines the FTP welcome message spans over... And this cannot be acceptable!</p>
  
  <pre><code>    private Socket connection;
      private PrintWriter outStream;
      private Scanner inStream;
  
  public void InitiateConnection() throws IOException 
  {
      log.Info(this, "Initiating connection to host: " + host + ":" + port);
      connection = new Socket(host, port);
      log.Info(this, "Connection initiated.");
      outStream = new PrintWriter(connection.getOutputStream(), true);
      inStream = new Scanner(connection.getInputStream());
      Listen();
      Listen();    
      Listen();
  }
  
  public String Listen() throws IOException
  {
      if(connection == null)
          throw new IOException("Connection not initiated yet");
      String response = inStream.nextLine();
      log.Info(this, "Response: " + response);
      return response;
  }
  </code></pre>
  
  <p>This is the simple setup, I have left out all other code, as it doesn't have anything to do with my problem.</p>
  
  <p>I have tried multiple things to try to achieve this.
  Failed Solution 1:</p>
  
  <pre><code>String response = "";
  while(response != null)
      Listen();
  </code></pre>
  
  <p>Failed Solution 2:</p>
  
  <pre><code>while(connection.getInputStream().available &gt; 0)
      Listen();
  </code></pre>
  
  <p>And countless others... But either it doesn't work, or the methods block and wait for new input. I have even tried with a timeout, but that doesn't work flawlessly either, its not a proper solution to this problem...</p>
  
  <p>I need to be able to get the entire welcome message from the FTP server, without knowing the amount of lines...
  So I can both get this:</p>
  
  <pre><code>Response:   220-FileZilla Server version 0.9.39 beta
  Response:   220-written by Tim Kosse (Tim.Kosse@gmx.de)
  Response:   220 Please visit http://sourceforge.net/projects/filezilla/
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>Response:   220-FileZilla Server version 0.9.40 beta
  Response:   220 Welcome to Andrés FTP Server
  </code></pre>