title: Commons Net FTP fails when transferring a directory, but works single file
body: <p>I have a Commons Net FTP file problem.  I have an application which can transfer either a single file or a directory to a remote host, depending on what the user clicked on in a JTree.  When I am transferring a particular directory, the transfer always fails on the same file, with a 'Software caused connection abort: socket write error'.  When I select the same file and transfer it as a single file, it works fine.  The relevant code for the directory transfer is:</p>
  
  <pre><code>BufferedOutputStream bos = new BufferedOutputStream(os,8*1024);
  if (filelen &gt; 500){
  buffer = new byte[(int) (filelen/100)];
  }else {
  buffer = new byte[(int) filelen];
  }
  int len; 
  BufferedInputStream bis = new BufferedInputStream(is,8*1024);
  int ba = bis.available();
  while ((len = bis.read(buffer)) != -1 &amp;&amp; ba != 0)  
  {
  //os.write(buffer, 0, len);
  System.out.println(ftp.getReplyString());
  System.out.println("len is "+len);
  System.out.println("ba is "+ba);
  System.out.println("first two bytes are "+buffer[0]+buffer[1]);
  System.out.println("last byte is "+buffer[buffer.length-1]);
  System.out.println("buffer length is "+buffer.length);
  int rc = ftp.getReplyCode();
  if (rc == 550){
  hftstatus.setText("Copy Error encountered, check log.");
  return;
  }
  bos.write(buffer,0, len);
  bos.flush();
  System.out.println(ftp.getReplyString());
  ba = bis.available();
  if (filelen &gt; 500){
  if (len &gt; 0){
  left -=len;
  totleft -=len;
     }
  }else{
  left=0;
  }
  if (ba &lt; buffer.length){
  buffer = new byte[ba];
  }
  double ip = (left*100)/filelen;
  int percomp =  (int) (100-ip);
  double ap = (totleft*100)/totlength;
  int perallcomp = (int) (100-ap);
  hftcurrfileprog.setValue(percomp);
  hftallfileprog.setValue(perallcomp);
  hftstatus.setText("Copying file "+f+" "+percomp+" percent completed.");
                  }
  </code></pre>
  
  <p>and the relevant code for a single file is:</p>
  
  <pre><code>    BufferedOutputStream bos = new BufferedOutputStream(os,8*1024);
      if (filelen &gt; 500){
      buffer = new byte[(int) (filelen/100)];
      }else {
      buffer = new byte[(int) filelen];
      }
      int len;
      while ((len = bis.read(buffer)) != -1)  
      {
          bos.write(buffer, 0, len);
          int rc = ftp.getReplyCode();
          if (rc == 550){hftstatus.setText("Copy Error encountered, check log.");}
          bos.flush();
          bytestran += len;
          if (filelen &gt; 100){
          left = left-(filelen/100);
          }else{
              left=0;
          }
          double ip = (left*100)/filelen;
          int percomp =  (int) (100-ip);
          hftcurrfileprog.setValue(percomp);
          hftallfileprog.setValue(percomp);
          if (bytestran == filelen){break;}
          }
          String outm = ftp.getReplyString();
          System.out.println(outm);
          bos.flush();
          bos.close();
          bis.close();
          os.close();
          is.close();
          ftp.completePendingCommand();
          System.out.println(ftp.getReplyString());
          totleft = 0;
          double ip = (left*100)/filelen;
          int percomp =  (int) (100-ip);
          int perallcomp = 100;
          hftcurrfileprog.setValue(percomp);
          hftallfileprog.setValue(perallcomp);
          hftstatus.setText("file "+fnode+" copied to directory "+remoteDirPath+nwd);
  </code></pre>
  
  <p>Any thoughts or clues would be much appreciated.   I many hits somewhat close to this, but none where the only difference is in directory or single file transfer.   Thank you for your help.</p>