Ejemplo n.º 1
0
  protected void get(boolean passive, RestartData restart, String remoteFile)
      throws IOException, FTPException {
    InputStreamDataSink sink = null;

    try {
      this.ftp.setType(Session.TYPE_IMAGE);
      if (passive) {
        this.ftp.setPassive();
        this.ftp.setLocalActive();
      } else {
        this.ftp.setLocalPassive();
        this.ftp.setActive();
      }
      if (null != restart) {
        this.ftp.setRestartMarker(restart);
      }

      sink = new InputStreamDataSink();
      this.input = sink.getInputStream();
      this.state = this.ftp.asynchGet(remoteFile, sink, null);
      this.state.waitForStart();
    } catch (FTPException e) {
      if (sink != null) {
        sink.close();
      }
      close();
      LogManager.debug("Current thread with closed socket is: " + Thread.currentThread().getName());
      throw e;
    }
  }
Ejemplo n.º 2
0
  public InputStream openInputStream(String name) throws FileResourceException {
    InputStreamDataSink sink = null;
    try {
      ftpClient.setPassive();
      ftpClient.setLocalActive();

      sink = new InputStreamDataSink();

      TransferState state = ftpClient.asynchGet(name, sink, null);
      state.waitForStart();

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