protected void changeCurrentDir(IPath path) throws FTPException, IOException {
   try {
     if (cwd == null) {
       cwd = new Path(ftpClient.pwd());
     }
     if (!cwd.equals(path)) {
       ftpClient.chdir(path.toPortableString());
       cwd = path;
     }
   } catch (FTPException e) {
     throwFileNotFound(e, path);
   } catch (IOException e) {
     cwd = null;
     throw e;
   }
 }
  /* (non-Javadoc)
   * @see com.aptana.ide.core.ftp.BaseFTPConnectionFileManager#writeFile(org.eclipse.core.runtime.IPath, long, org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  protected OutputStream writeFile(IPath path, long permissions, IProgressMonitor monitor)
      throws CoreException, FileNotFoundException {
    monitor.beginTask(Messages.FTPConnectionFileManager_initiating_file_upload, 4);
    FTPClient uploadFtpClient = (FTPClient) pool.checkOut();
    try {
      initAndAuthFTPClient(uploadFtpClient, monitor, false);
      Policy.checkCanceled(monitor);
      setMessageLogger(uploadFtpClient, messageLogWriter);
      uploadFtpClient.setType(
          IFTPConstants.TRANSFER_TYPE_ASCII.equals(transferType)
              ? FTPTransferType.ASCII
              : FTPTransferType.BINARY);
      IPath dirPath = path.removeLastSegments(1);
      try {
        uploadFtpClient.chdir(dirPath.toPortableString());
      } catch (FTPException e) {
        throwFileNotFound(e, dirPath);
      }
      monitor.worked(1);
      Policy.checkCanceled(monitor);
      return new FTPFileUploadOutputStream(
          pool,
          uploadFtpClient,
          new FTPOutputStream(uploadFtpClient, generateTempFileName(path.lastSegment())),
          path.lastSegment(),
          null,
          permissions);
    } catch (Exception e) {
      setMessageLogger(uploadFtpClient, null);
      pool.checkIn(uploadFtpClient);

      if (e instanceof OperationCanceledException) {
        throw (OperationCanceledException) e;
      } else if (e instanceof FileNotFoundException) {
        throw (FileNotFoundException) e;
      } else if (e instanceof FTPException) {
        if (((FTPException) e).getReplyCode() == 553) {
          throw (FileNotFoundException)
              new FileNotFoundException(path.toPortableString()).initCause(e);
        }
      }
      if (connectionRetryCount < 1) {
        connectionRetryCount++;
        try {
          initAndAuthFTPClient(uploadFtpClient, monitor, true);
        } catch (IOException e1) {
          // ignores
        } catch (FTPException e1) {
          // ignores
        }
        try {
          return writeFile(path, permissions, monitor);
        } finally {
          connectionRetryCount = 0;
        }
      } else {
        connectionRetryCount = 0;
        throw new CoreException(
            new Status(
                Status.ERROR,
                FTPPlugin.PLUGIN_ID,
                Messages.FTPConnectionFileManager_opening_file_failed,
                e));
      }
    } finally {
      monitor.done();
    }
  }
  /* (non-Javadoc)
   * @see com.aptana.ide.core.ftp.BaseFTPConnectionFileManager#readFile(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  protected InputStream readFile(IPath path, IProgressMonitor monitor)
      throws CoreException, FileNotFoundException {
    monitor.beginTask(Messages.FTPConnectionFileManager_initiating_download, 4);
    FTPClient downloadFtpClient = (FTPClient) pool.checkOut();
    try {
      initAndAuthFTPClient(downloadFtpClient, monitor, false);
      Policy.checkCanceled(monitor);
      setMessageLogger(downloadFtpClient, messageLogWriter);
      downloadFtpClient.setType(
          IFTPConstants.TRANSFER_TYPE_ASCII.equals(transferType)
              ? FTPTransferType.ASCII
              : FTPTransferType.BINARY);
      try {
        downloadFtpClient.chdir(path.removeLastSegments(1).toPortableString());
      } catch (FTPException e) {
        throwFileNotFound(e, path.removeLastSegments(1));
      }
      monitor.worked(1);
      Policy.checkCanceled(monitor);
      try {
        return new FTPFileDownloadInputStream(
            pool, downloadFtpClient, new FTPInputStream(downloadFtpClient, path.lastSegment()));
      } catch (FTPException e) {
        throwFileNotFound(e, path);
        return null;
      }
    } catch (Exception e) {
      setMessageLogger(downloadFtpClient, null);
      pool.checkIn(downloadFtpClient);

      if (e instanceof OperationCanceledException) {
        throw (OperationCanceledException) e;
      } else if (e instanceof FileNotFoundException) {
        throw (FileNotFoundException) e;
      }
      // does one retry
      if (connectionRetryCount < 1) {
        connectionRetryCount++;
        try {
          initAndAuthFTPClient(downloadFtpClient, monitor, true);
        } catch (IOException e1) {
          // ignores
        } catch (FTPException e1) {
          // ignores
        }
        try {
          return readFile(path, monitor);
        } finally {
          connectionRetryCount = 0;
        }
      } else {
        connectionRetryCount = 0;
        throw new CoreException(
            new Status(
                Status.ERROR,
                FTPPlugin.PLUGIN_ID,
                Messages.FTPConnectionFileManager_opening_file_failed,
                e));
      }
    } finally {
      monitor.done();
    }
  }