title: java.net.SocketException: Permission denied: recv failed
body: <p>i am a beginner programmer in this networking java concept wherein you connect to a remote ftp server and carry out trivial tasks.</p>
  
  <p>here is my code</p>
  
  <pre><code>import java.io.BufferedOutputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  
  import org.apache.commons.net.ftp.FTP;
  import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPReply;
  
  
  public class SimpleOne {
  
      static String serverName = "ftp.drivehq.com";
      static int port = 21;
      static String username = "CANTSHOW";
      static String password = "CANTSHOW";
      public static void main(String[] args) throws IOException{
          FTPClient ftpc = new FTPClient();
          ftpc.connect(serverName, port);
          int reply = ftpc.getReplyCode();
          String sReply = ftpc.getReplyString();
          if(!FTPReply.isPositiveCompletion(reply))
          {
              System.out.println("Some error!");
              return;
          }
          boolean success = ftpc.login(username, password);
          if(success)
          {
              System.out.println("Login successful!");
              System.out.println(sReply);
              ftpc.enterLocalPassiveMode();
              String dir=ftpc.printWorkingDirectory();
              System.out.println(dir);
              success = ftpc.changeWorkingDirectory("My Documents");
              if(success)
              {
                  System.out.println(ftpc.printWorkingDirectory());
                  ftpc.setFileType(FTP.BINARY_FILE_TYPE);
                  String remoteFile = "SampleText.txt";
                  File localFile = new File("sample.txt");
                  OutputStream localOutputStream = new BufferedOutputStream(new FileOutputStream(localFile));
                  success=ftpc.retrieveFile(remoteFile, localOutputStream);//&lt;--- ERROR LINE
                  localOutputStream.close();
                  if(!success)
                  {
                      System.out.println("There was some problem in retrieving the file");
                      return;
                  }
                  System.out.println("File was downloaded!");
              }
              else
              {
                  System.out.println("Could not change directory!");
              }
          }
          else
          {
              System.out.println("Login failed!");
          }
      }
  
  }
  </code></pre>
  
  <p>and here is what my output looks like:</p>
  
  <pre><code>Login successful!
  220 Welcome to the most popular FTP hosting service! Save on hardware, software, hosting and admin. Share files/folders with read-write permission. Visit http://www.drivehq.com/ftp/;
  
  /
  /My Documents
  Exception in thread "main" java.net.SocketException: Permission denied: recv failed
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.read(SocketInputStream.java:152)
      at java.net.SocketInputStream.read(SocketInputStream.java:122)
      at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
      at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
      at java.io.InputStreamReader.read(InputStreamReader.java:184)
      at java.io.BufferedReader.fill(BufferedReader.java:154)
      at java.io.BufferedReader.read(BufferedReader.java:175)
      at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:314)
      at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
      at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
      at org.apache.commons.net.ftp.FTP.pasv(FTP.java:1007)
      at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:869)
      at org.apache.commons.net.ftp.FTPClient._retrieveFile(FTPClient.java:1854)
      at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1845)
      at SimpleOne.main(SimpleOne.java:44)
  </code></pre>
  
  <p>What all i have tried:</p>
  
  <ol>
  <li><p>i googled this issue, found that it was filed as an official bug and Microsoft released a hotfix. i downloaded that hotfix, but the installer said that it was not for my windows version (btw, i use win7 x86 and jdk 1.7.0_67)</p></li>
  <li><p>i updated my windows, and downloaded all updates</p></li>
  <li><p>i allowed java.exe and javaw.exe in my firewall in both inbound and outbound connection types</p></li>
  </ol>
  
  <p>please help me, i am completely stuck here.</p>
  
  <p>Note: as i am still learning, i haven't written that part of code where you logout and disconnect. i hope it has nothing to do with this error.</p>