public void rename(String currentPath, String newPath) throws ClientCommandRenameException { logger.debug("rename called with currentPath [" + currentPath + "], newPath [" + newPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ try { String dirBefore = this.ftpClient.printWorkingDirectory(); logger.debug("Working directory before rename = [" + dirBefore + "]"); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Current Path = [" + currentPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("New Path = [" + newPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ if(!this.ftpClient.rename(currentPath, newPath)) { throw new ClientCommandRenameException("Failed to rename [" + currentPath + "] to [" + newPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } logger.debug("Successfully renamed [" + currentPath + "] to [" //$NON-NLS-1$ //$NON-NLS-2$ + newPath + "]"); //$NON-NLS-1$ String dirAfter = this.ftpClient.printWorkingDirectory(); logger.debug("Working directory after rename = [" + dirAfter + "]"); //$NON-NLS-1$ //$NON-NLS-2$ if(!dirBefore.equals(dirAfter)) { this.ftpClient.changeWorkingDirectory(dirBefore); logger.debug("Returning to previous working = [" + dirBefore + "]"); //$NON-NLS-1$//$NON-NLS-2$ } } catch (IOException e) { throw new ClientCommandRenameException("Failed to rename [" + currentPath + "] to [" + newPath + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
/** * Rename the file from oldPath to newPath * * @param oldPath Original Path * @param newPath New Path * @throws ResourceException when renaming a file fails */ protected void renameFile(String oldPath, String newPath) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("Renaming file from [" + oldPath + "] to [" //$NON-NLS-1$ //$NON-NLS-2$ + newPath + "]"); //$NON-NLS-1$ } try { getClient().ensureConnection(); this.getClient().rename(oldPath, newPath); } catch (ClientCommandRenameException e) { logger.warn("Failed to rename file [" + oldPath //$NON-NLS-1$ + "] to [" + newPath //$NON-NLS-1$ + "]. Exception occured [" + e.getMessage() + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ throw new ResourceException(e); } }
public void rename(String currentPath, String newPath) throws ClientCommandRenameException { logger.debug("rename called with currentPath [" + currentPath + "], newPath [" + newPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ try { String dirBefore = this.ftpClient.printWorkingDirectory(); logger.debug("Working directory before rename = [" + dirBefore + "]"); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Current Path = [" + currentPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("New Path = [" + newPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ if(!this.ftpClient.rename(currentPath, newPath)) { throw new ClientCommandRenameException("Failed to rename [" + currentPath + "] to [" + newPath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } logger.debug("Successfully renamed [" + currentPath + "] to [" //$NON-NLS-1$ //$NON-NLS-2$ + newPath + "]"); //$NON-NLS-1$ String dirAfter = this.ftpClient.printWorkingDirectory(); logger.debug("Working directory after rename = [" + dirAfter + "]"); //$NON-NLS-1$ //$NON-NLS-2$ if(!dirBefore.equals(dirAfter)) { this.ftpClient.changeWorkingDirectory(dirBefore); logger.debug("Returning to previous working = [" + dirBefore + "]"); //$NON-NLS-1$//$NON-NLS-2$ } } catch (IOException e) { throw new ClientCommandRenameException("Failed to rename [" + currentPath + "] to [" + newPath + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } }
sb.append(']'); sb.trimToSize(); throw new ClientCommandRenameException(sb.toString(), e);