Exemple #1
0
  /** Sets remote server to striped passive server mode (SPAS). */
  public HostPortList setStripedPassive() throws IOException, ServerException {
    Command cmd = new Command("SPAS", (controlChannel.isIPv6()) ? "2" : null);
    Reply reply = null;

    try {
      reply = controlChannel.execute(cmd);
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }

    this.gSession.serverMode = GridFTPSession.SERVER_EPAS;
    if (controlChannel.isIPv6()) {
      gSession.serverAddressList = HostPortList.parseIPv6Format(reply.getMessage());
      int size = gSession.serverAddressList.size();
      for (int i = 0; i < size; i++) {
        HostPort6 hp = (HostPort6) gSession.serverAddressList.get(i);
        if (hp.getHost() == null) {
          hp.setVersion(HostPort6.IPv6);
          hp.setHost(controlChannel.getHost());
        }
      }
    } else {
      gSession.serverAddressList = HostPortList.parseIPv4Format(reply.getMessage());
    }
    return gSession.serverAddressList;
  }
Exemple #2
0
  /**
   * Establishes a secure and authenticated context with the server.
   *
   * @param factory factory for creating the DssContext of the secure session
   * @param username specific username to authenticate as.
   * @throws IOException on i/o error
   * @throws ServerException on server refusal or faulty server behavior
   */
  public void authenticate(DssContextFactory factory, String username)
      throws IOException, ServerException {
    try {
      // authenticate
      GridFTPControlChannel gridFTPControlChannel =
          new GridFTPControlChannel(controlChannel, factory, expectedHostName);

      // from now on, the commands and replies
      // are protected and pass through gsi wrapped socket

      // login
      try {
        Reply reply =
            gridFTPControlChannel.exchange(
                new Command("USER", (username == null) ? ":globus-mapping:" : username));
        // wu-gsiftp sends intermediate code while
        // gssftp send completion reply code
        if (!Reply.isPositiveCompletion(reply) && !Reply.isPositiveIntermediate(reply)) {
          throw ServerException.embedUnexpectedReplyCodeException(
              new UnexpectedReplyCodeException(reply), "User authorization failed.");
        }
      } catch (FTPReplyParseException rpe) {
        throw ServerException.embedFTPReplyParseException(
            rpe, "Received faulty reply to USER command.");
      }

      try {
        Reply reply = gridFTPControlChannel.exchange(new Command("PASS", "dummy"));
        if (!Reply.isPositiveCompletion(reply)) {
          throw ServerException.embedUnexpectedReplyCodeException(
              new UnexpectedReplyCodeException(reply), "Bad password.");
        }
      } catch (FTPReplyParseException rpe) {
        throw ServerException.embedFTPReplyParseException(
            rpe, "Received faulty reply to PASS command.");
      }

      this.gSession.authorized = true;
      this.username = username;
      this.controlChannel = gridFTPControlChannel;

      // quietly send version information to the server.
      // ignore errors
      try {
        this.site(usageString);
      } catch (Exception ex) {
      }

    } catch (ServerException | IOException e) {
      close();
      throw e;
    }
  }
Exemple #3
0
  /**
   * Computes and returns a checksum of a file. transferred.
   *
   * @param algorithm the checksume algorithm
   * @param offset the offset
   * @param length the length
   * @param file file to compute checksum of
   * @return the computed checksum
   * @throws ServerException if an error occured.
   */
  public String checksum(ChecksumAlgorithm algorithm, long offset, long length, String file)
      throws IOException, ServerException {
    String arguments =
        algorithm.toFtpCmdArgument()
            + " "
            + String.valueOf(offset)
            + " "
            + String.valueOf(length)
            + " "
            + file;

    Command cmd = new Command("CKSM", arguments);
    Reply reply = null;
    try {
      reply = controlChannel.execute(cmd);
      return reply.getMessage();
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }
  }