Exemple #1
0
  /**
   * Upload a local file to a URL
   *
   * @return true if successful
   */
  public boolean upload(String fileName, String url) {
    Data remote = Data.factory(url);
    Data local = Data.factory(fileName);

    // Sanity checks
    if (!remote.isRemote()) {
      System.err.println("Cannot upload to non-remote URL: " + url);
      return false;
    }

    if (!local.isFile()) {
      System.err.println("Cannot upload non-file: " + fileName);
      return false;
    }

    if (!local.exists()) {
      System.err.println("Local file does not exists: " + fileName);
      return false;
    }

    if (!local.canRead()) {
      System.err.println("Cannot read local file : " + fileName);
      return false;
    }

    // Already uploaded? Nothing to do
    if (remote.isUploaded(fileName)) {
      if (verbose) System.err.println("Remote file is up to date, no upload required: " + url);
      return true;
    }

    return remote.upload(fileName);
  }
Exemple #2
0
  /**
   * Download a URL to a local file
   *
   * @return true if successful
   */
  public boolean download(String url, String fileName) {
    Data remote = Data.factory(url);

    // Sanity checks
    if (!remote.isRemote()) {
      System.err.println("Cannot download non-remote URL: " + url);
      return false;
    }

    if (!remote.isFile()) {
      System.err.println("Cannot download non-file: " + url);
      return false;
    }

    // Already downloaded? Nothing to do
    if (remote.isDownloaded(fileName)) {
      if (verbose)
        System.err.println("Local file is up to date, no download required: " + fileName);
      return true;
    }

    return remote.download(fileName);
  }