private String getServername(PropertyList propertyList) throws FTPException {

    Property hostProperty = PropertyHelper.getFromList(propertyList, "SERVERNAME");

    if (hostProperty == null || hostProperty.getType() != PropertyType.TEXT) {
      throw new FTPException("No servername provided for FTP-Connection");
    }
    return ((TextProperty) hostProperty).getValue().getValue();
  }
    public PropertyIterator(Property iterableProperty) throws TestScriptException {

      if (iterableProperty instanceof PropertyComposite) {
        this.property = (PropertyComposite) iterableProperty;
      } else {
        throw new TestScriptException(
            "Cannot iterate over '"
                + iterableProperty.getName().getValue()
                + "' -> invalid type: "
                + iterableProperty.getType());
      }
    }
  private int getPort(PropertyList propertyList) {

    Property portProperty = PropertyHelper.getFromList(propertyList, "PORT");

    if (portProperty == null) {
      return FTPClient.DEFAULT_PORT;
    }

    switch (portProperty.getType()) {
      case NUMERIC:
        return ((NumericProperty) portProperty).getValue().getValue().intValue();
      case TEXT:
        String value = ((TextProperty) portProperty).getValue().getValue();
        try {
          return Integer.parseInt(value);
        } catch (NumberFormatException ex) {
          return FTPClient.DEFAULT_PORT;
        }
      default:
        return FTPClient.DEFAULT_PORT;
    }
  }
  /** {@inheritDoc} */
  @Override
  public void visit(Foreach foreach, TestScriptResult argument) throws TestScriptException {
    getContext().setCurrentTestScriptElement(foreach);
    Name elementName = foreach.getElementName();
    PropertyReference iterableId = foreach.getIterableRef();
    Property iterableProperty = getContext().getProperty(iterableId);

    if (iterableProperty == null) {
      throw new TestScriptException("Property '" + iterableId + "' not found in context");
    }

    PropertyIterator propertyIterator = new PropertyIterator(iterableProperty);

    if (getContext().getProperty(elementName) != null) {
      throw new TestScriptException(
          "Foreach configuration error -> Property '"
              + elementName
              + "' already exists in context");
    }

    logger.info("Starting Foreach-Loop: " + foreach.getId());
    Iterator<Property> iterator = propertyIterator.iterator();
    Property currentProp = null;

    while (iterator.hasNext()) {
      currentProp = iterator.next();

      if (logger.isDebugEnabled()) {
        logger.debug(
            "Next element: id="
                + currentProp.getName().getValue()
                + ", type="
                + currentProp.getType());
      }

      Property currentClone = currentProp.cloneObject();
      currentClone.setName(elementName);
      getContext().put(currentClone);

      try {
        super.visit(foreach.getTestScriptElementList(), argument);
      } catch (BreakLoopException ex) {
        getContext().remove(currentClone);
        break;
      }

      // remove property with id=elementId from context
      getContext().remove(currentClone);
    }
  }