Exemplo n.º 1
0
 /** rename a remote file. */
 public void rename(String remoteFileName1, String remoteFileName2) throws FileResourceException {
   try {
     ftpClient.rename(remoteFileName1, remoteFileName2);
   } catch (Exception e) {
     throw translateException("Rename for ftp failed", e);
   }
 }
Exemplo n.º 2
0
  /**
   * Renames the file denoted by this abstract pathname.
   *
   * <p>Whether or not this method can move a file from one filesystem to another is
   * platform-dependent. The return value should always be checked to make sure that the rename
   * operation was successful.
   *
   * @param dest The new abstract pathname for the named file
   * @throws IllegalArgumentException If parameter <code>dest</code> is not a <code>GeneralFile
   *     </code>.
   * @throws NullPointerException - If dest is null
   */
  public boolean renameTo(GeneralFile dest) throws IllegalArgumentException, NullPointerException {
    try {
      if (dest instanceof FTPFile) {
        if (ftpClient.equals(((FTPFile) dest).ftpClient)) {
          ftpClient.rename(getPath(), dest.getPath());
        } else {
          // TODO some ftp to ftp copy...

          if (!dest.exists()) {
            copyTo(dest);
            delete();
          } else return false;
        }
      } else {
        if (!dest.exists()) {
          copyTo(dest);
          delete();
        } else return false;
      }
    } catch (IOException e) {
      return false;
    } catch (FTPException e) {
      return false;
    }

    return true;
  }