title: Reading files using java FTPClient
body: <p>I am using FTPClient to do FTP on one of server. I am able to get all the list of the files but when I am tryto read those file it is showing "connection closed", "connection refused", "connection reset" exception. I am using following code for FTP</p>
  
  <pre><code>  FTPClient client = new FTPClient();
    client.connect("IpAddress");
    client.login("Username", "Password");
    client.setRemoteVerificationEnabled(false);
    client.enterLocalPassiveMode();
    FTPFile[] files = client.listFiles(dirPath);
  </code></pre>
  
  <p>above code is givng me all the file names then I passing these name in my search object. There I am using same "client" object</p>
  
  <pre><code> InputStream in = client.retrieveFileStream("filename with path as a string");
   try(BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
         while (null != reader &amp;&amp; (line = reader.readLine()) != null) {
              if (null != line &amp;&amp; line.contains(wordToSearch)) {
                System.out.println("word Found");
              }
          }
  </code></pre>
  
  <p>that folder contains too many files. I am able to fetch all the files why is it failing when reading them.</p>
  
  <p>Exception is :</p>
  
  <pre><code>java.net.ConnectException: Connection refused: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
  22:57:22,594  INFO Connector:38 - Traversing and Searching Finished......
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:579)
      at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:894)
      at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:759)
      at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3293)
      at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
      at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
      at com.novigolabs.connectors.FtpConnector.listFiles(FtpConnector.java:44)
      at com.novigolabs.connectors.FtpConnector.listFiles(FtpConnector.java:55)
      at com.novigolabs.search.Traverse.initiateSearch(Traverse.java:117)
      at com.novigolabs.search.Traverse.run(Traverse.java:45)
      at java.lang.Thread.run(Thread.java:724)
  </code></pre>