Example #1
0
  protected void put(boolean passive, int type, String remoteFile, boolean append)
      throws IOException, FTPException {
    OutputStreamDataSource source = null;
    try {
      this.ftp.setType(type);

      if (passive) {
        this.ftp.setPassive();
        this.ftp.setLocalActive();
      } else {
        this.ftp.setLocalPassive();
        this.ftp.setActive();
      }

      source = new OutputStreamDataSource(2048);

      this.state = this.ftp.asynchPut(remoteFile, source, null, append);

      this.state.waitForStart();

      this.output = source.getOutputStream();
    } catch (FTPException e) {
      if (source != null) {
        source.close();
      }
      close();
      throw e;
    }
  }
Example #2
0
  public OutputStream openOutputStream(String name) throws FileResourceException {
    OutputStreamDataSource source = null;
    try {
      ftpClient.setPassive();
      ftpClient.setLocalActive();

      source = new OutputStreamDataSource(16384);

      TransferState state = ftpClient.asynchPut(name, source, null, false);
      state.waitForStart();

      return source.getOutputStream();
    } catch (Exception e) {
      if (source != null) {
        try {
          source.close();
        } catch (IOException ee) {
          logger.warn("Failed to close FTP source", ee);
        }
      }
      throw translateException("Failed to open FTP stream", e);
    }
  }