title: Store ObjectOutputStream in FTP causes java.net.SocketException: Software caused connection abort: socket write error
body: <p>I am trying to store an custom defined (ProjectData) Java object in a file in FTP . ProjectData class implements Serializable interface.I am using apache Commons Net FTP client.I have a custom class FtpClient , which has instance of Commons net FTP Client. I  connect , upload file,  download file, storeFileStream using this class.When I try to call 
  saveProjectData function, it throws exception while executing save.writeObject(data).</p>
  
  <pre><code>java.net.SocketException: Software caused connection abort: socket write error
  at java.net.SocketOutputStream.socketWrite0(Native Method) [:1.6.0_23]
  at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) [:1.6.0_23]
  at java.net.SocketOutputStream.write(SocketOutputStream.java:136) [:1.6.0_23]
  at org.apache.commons.net.io.SocketOutputStream.write(SocketOutputStream.java:72) [:2.2]
  at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847) [:1.6.0_23]
  at java.io.ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream.java:1792) [:1.6.0_23]
  at java.io.ObjectOutputStream.flush(ObjectOutputStream.java:699) [:1.6.0_23]
  </code></pre>
  
  <p>So what is the problem in the code, I ready that connection is already closed, in the meantime of saving object.But I could not find where the bug.</p>
  
  <pre><code>public void saveProjectData(ProjectData data, String filePath) {
      ftpClient = new FtpClient(ftpConfig, logger);
      ObjectOutputStream save = null;
      try {
          ftpClient.connect();
          save = new ObjectOutputStream(ftpClient.storeFileStream(filePath));
      } catch (Exception e) {
          // ignore
      }
      try {
          if (save == null) {
              ftpClient.reconnect();
              save = new ObjectOutputStream(ftpClient.storeFileStream(filePath));
          }
          save.writeObject(data);
          save.flush();
      } catch (IOException e) {
          logger.error("Error creating file:" + filePath);
          throw new FileTransferException("Could not create file:" + filePath, e);
      } finally {
          if (save != null) {
              try {
                  save.close();
              } catch (Exception e) {
                  logger.warn("Error closing writer of file:" + filePath, e);
              }
              save = null;
          }
          if (ftpClient != null) {
              try {
                  ftpClient.disconnect();
              } catch (Exception e) {
                  // ignore
              }
              ftpClient = null;
          }
      }
  }
  
      /**
   * Stores the file in FTP
   * @param filePath
   * @return
   */
  public OutputStream storeFileStream(String filePath) {
      try {
          client.setFileType(FTP.BINARY_FILE_TYPE);
          return client.storeFileStream(filePath);
      } catch (Exception ioe) {
          log.warn("Could not store file:" + filePath, ioe);
          return null;
      }
  }
  </code></pre>