Ejemplo n.º 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;
  }
Ejemplo n.º 2
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);
    }
  }