예제 #1
0
  /**
   * Sets data channel protection level (PROT).
   *
   * @param protection should be {@link GridFTPSession#PROTECTION_CLEAR CLEAR}, {@link
   *     GridFTPSession#PROTECTION_SAFE SAFE}, or {@link GridFTPSession#PROTECTION_PRIVATE PRIVATE},
   *     or {@link GridFTPSession#PROTECTION_CONFIDENTIAL CONFIDENTIAL}.
   */
  public void setDataChannelProtection(int protection) throws IOException, ServerException {

    String protectionStr = null;
    switch (protection) {
      case GridFTPSession.PROTECTION_CLEAR:
        protectionStr = "C";
        break;
      case GridFTPSession.PROTECTION_SAFE:
        protectionStr = "S";
        break;
      case GridFTPSession.PROTECTION_CONFIDENTIAL:
        protectionStr = "E";
        break;
      case GridFTPSession.PROTECTION_PRIVATE:
        protectionStr = "P";
        break;
      default:
        throw new IllegalArgumentException("Bad protection: " + protection);
    }

    Command cmd = new Command("PROT", protectionStr);
    try {
      controlChannel.execute(cmd);
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }

    this.gSession.dataChannelProtection = protection;

    gLocalServer.setDataChannelProtection(protection);
  }
예제 #2
0
  /**
   * Change the modification time of a file.
   *
   * @param year Modifcation year
   * @param month Modification month (1-12)
   * @param day Modification day (1-31)
   * @param hour Modification hour (0-23)
   * @param min Modification minutes (0-59)
   * @param sec Modification seconds (0-59)
   * @param file file whose modification time should be changed
   * @throws IOException
   * @throws ServerException if an error occurred.
   */
  public void changeModificationTime(
      int year, int month, int day, int hour, int min, int sec, String file)
      throws IOException, ServerException {
    DecimalFormat df2 = new DecimalFormat("00");
    DecimalFormat df4 = new DecimalFormat("0000");

    String arguments =
        df4.format(year)
            + df2.format(month)
            + df2.format(day)
            + df2.format(hour)
            + df2.format(min)
            + df2.format(sec)
            + " "
            + file;
    Command cmd = new Command("SITE UTIME", arguments);

    try {
      controlChannel.execute(cmd);
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }
  }
예제 #3
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;
  }
예제 #4
0
 /**
  * Change the Unix group membership of a file.
  *
  * @param group the name or ID of the group
  * @param file the file whose group membership should be changed
  * @throws ServerException if an error occurred.
  */
 public void changeGroup(String group, String file) throws IOException, ServerException {
   String arguments = group + " " + file;
   Command cmd = new Command("SITE CHGRP", arguments);
   try {
     controlChannel.execute(cmd);
   } catch (UnexpectedReplyCodeException urce) {
     throw ServerException.embedUnexpectedReplyCodeException(urce);
   } catch (FTPReplyParseException rpe) {
     throw ServerException.embedFTPReplyParseException(rpe);
   }
 }
예제 #5
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;
    }
  }
예제 #6
0
  /**
   * Sets the checksum values ahead of the transfer
   *
   * @param algorithm the checksume algorithm
   * @param value the checksum value as hexadecimal number
   * @return nothing
   * @throws ServerException if an error occured.
   */
  public void setChecksum(ChecksumAlgorithm algorithm, String value)
      throws IOException, ServerException {
    String arguments = algorithm.toFtpCmdArgument() + " " + value;

    Command cmd = new Command("SCKS", arguments);
    try {
      controlChannel.execute(cmd);
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }
  }
예제 #7
0
  /** Sets remote server to striped active server mode (SPOR). */
  public void setStripedActive(HostPortList hpl) throws IOException, ServerException {
    Command cmd = new Command("SPOR", hpl.toFtpCmdArgument());

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

    this.gSession.serverMode = GridFTPSession.SERVER_EACT;
  }
예제 #8
0
  /**
   * Create a symbolic link on the FTP server.
   *
   * @param link_target the path to which the symbolic link should point
   * @param link_name the path of the symbolic link to create
   * @throws IOException
   * @throws ServerException if an error occurred.
   */
  public void createSymbolicLink(String link_target, String link_name)
      throws IOException, ServerException {

    String arguments = link_target.replaceAll(" ", "%20") + " " + link_name;
    Command cmd = new Command("SITE SYMLINK", arguments);

    try {
      controlChannel.execute(cmd);
    } catch (UnexpectedReplyCodeException urce) {
      throw ServerException.embedUnexpectedReplyCodeException(urce);
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }
  }
예제 #9
0
  /**
   * Sets data channel authentication mode (DCAU)
   *
   * @param type for 2-party transfer must be DataChannelAuthentication.SELF or
   *     DataChannelAuthentication.NONE
   */
  public void setDataChannelAuthentication(DataChannelAuthentication type)
      throws IOException, ServerException {

    Command cmd = new Command("DCAU", type.toFtpCmdArgument());
    try {

      controlChannel.execute(cmd);

    } catch (UnexpectedReplyCodeException urce) {
      if (!type.toFtpCmdArgument().equals("N")) {
        throw ServerException.embedUnexpectedReplyCodeException(urce);
      }
    } catch (FTPReplyParseException rpe) {
      throw ServerException.embedFTPReplyParseException(rpe);
    }

    this.gSession.dataChannelAuthentication = type;

    gLocalServer.setDataChannelAuthentication(type);
  }
예제 #10
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);
    }
  }