/** * Execute a change directory on the server to directory passed in * * @param path Path to change directory to * @throws ResourceException - */ protected void changeDirectory(String path) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("cd to dir [" + path + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { getClient().cd(path); } catch (ClientCommandCdException e) { logger.warn("Underlying File Transfer operation failed [CD]!", e); //$NON-NLS-1$ throw new ResourceException(e); } }
/** * Deletes a remote directory * * @param directoryPath - directory to be removed * @param recurse - flag to delete directory recursively or not. * @throws ResourceException when deleting a file fails */ protected void deleteDir(String directoryPath, boolean recurse) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("Deleting directory [" + directoryPath + "]"); //$NON-NLS-1$//$NON-NLS-2$ } try { getClient().deleteRemoteDirectory(directoryPath, recurse); } catch (ClientException e) { logger.warn("Underlying File Transfer operation failed [RMDIR]!", e); //$NON-NLS-1$ throw new ResourceException("Exception thrown when trying to delete directory [" + directoryPath + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ } catch (ClientCommandLsException e) { throw new ResourceException(e); } }
/** * Deletes a remote file * * @param filename - for file to be deleted * @throws ResourceException when removing a file fails */ protected void deleteFile(String filename) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("Deleting file [" + filename + "]"); //$NON-NLS-1$//$NON-NLS-2$ } try { getClient().ensureConnection(); getClient().deleteRemoteFile(filename); } catch (ClientException e) { logger.warn("Underlying File Transfer operation failed [RM]!", e); //$NON-NLS-1$ throw new ResourceException("Exception thrown when trying to delete file [" + filename + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ } }
/** * 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); } }
client.ensureConnection(); String originalDirectory = printWorkingDirectoryName(); if(!this.outputDirectory.equals(".") && !this.outputDirectory.equals(originalDirectory)) client.disconnect(); logger.info("Disconnected.");
/** * Get the SFYPMapped record that is a representation of the file * * @param filePath The path to the file * @return The BaseFileTransferMappedRecord representing the file * @throws ResourceException - failure to perform get */ protected BaseFileTransferMappedRecord getFile(String filePath) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("getFile called with: [" + filePath + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { return getClient().get(filePath); } catch (ClientCommandGetException e) { logger.warn("Underlying File Transfer operation failed [GET]!", e); //$NON-NLS-1$ throw new ResourceException(e); } }
List<ClientListEntry> result = new ArrayList<ClientListEntry>(); getClient().ensureConnection();
/** * Return a list of ClientListEntry objects * * @param directory The directory we are listing on * @return A list of ClientListEntry * @throws ResourceException - */ protected List<ClientListEntry> listDirectory(String directory) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("Listing directory [" + directory + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { return getClient().ls(directory); } catch (ClientCommandLsException e) { logger.warn("Underlying File Transfer operation failed [LS]!", e); //$NON-NLS-1$ throw new ResourceException(e); } catch (URISyntaxException e) { logger.warn("An URI Syntax exception occurred!", e); //$NON-NLS-1$ throw new ResourceException(e); } }
public InputStream sourceChunkableData(String remoteDir, String fileName) throws ChunkableDataSourceException { try { return getClient().getAsInputStream(remoteDir + fileName); } catch (ClientCommandGetException e) { throw new ChunkableDataSourceException("Exception whilst performing file transfer get ", e); //$NON-NLS-1$ } }
/** * Get the content from the file as an InputStream * * @param entry - the file * @return content as an InputStream * @throws ResourceException when downloding a file gails */ protected InputStream getContentAsStream(ClientListEntry entry) throws ResourceException { if(logger.isDebugEnabled()) { logger.debug("Getting content from [" + entry.getUri().getPath() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { return getClient().getContentAsStream(entry); } catch (ClientCommandGetException e) { logger.warn("Underlying File Transfer operation failed [GET]!", e); //$NON-NLS-1$ throw new ResourceException(e); } }
try getClient().mkdir(this.outputDirectory); changeDirectory(this.outputDirectory); changeDirectory = true;
public void sourceChunkableData(String remoteDir, String fileName, OutputStream outputStream, long offset) throws ChunkableDataSourceException { try { if (offset > 0) { // TODO Remove hard coded '1' and replace with value that means RESUME getClient().get(remoteDir + fileName, outputStream, 1, offset); } else { getClient().get(remoteDir + fileName, outputStream); } } catch (ClientCommandGetException e) { throw new ChunkableDataSourceException("Exception whilst performing file transfer get ", e); //$NON-NLS-1$ } }
/** * (non-Javadoc) Needs to move everything out of the temp directory to which * it was delivered, to its final destination * * @see org.ikasan.connector.base.command.AbstractTransactionalResourceCommand#doCommit() */ @Override protected void doCommit() throws ResourceException { try { logger.info("commit called on this command:" + this + "]"); //$NON-NLS-1$ //$NON-NLS-2$); getClient().ensureConnection(); String originalDirectory = printWorkingDirectoryName(); changeDirectory(outputDirectory); renameFile(tempDirectory, batchFolder); changeDirectory(originalDirectory); } catch(ResourceException exception) { TransactionCommitException transactionCommitException = new TransactionCommitException(exception); super.notifyListeners(transactionCommitException); throw exception; } }
public long getFileSize(String remoteDir, String fileName) throws ChunkableDataSourceException { List<ClientListEntry> entries = null; try { entries = getClient().ls(remoteDir + fileName); if (entries.size() != 1) { // We have failed to uniquely identify the file throw new ChunkableDataSourceException("Could not uniquely find file: [" //$NON-NLS-1$ + fileName + "], in remote dir: [" + remoteDir + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (ClientCommandLsException e) { throw new ChunkableDataSourceException("Could not perform ls over file transfer for file: [" //$NON-NLS-1$ + fileName + "], in remote dir: [" + remoteDir + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ } catch (URISyntaxException e) { throw new ChunkableDataSourceException("Could not perform ls over file transfer for file: [" //$NON-NLS-1$ + fileName + "], in remote dir:" + remoteDir + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ } ClientListEntry lsEntry = entries.get(0); return lsEntry.getSize(); }
/** * Get the Mapped record that is a representation of the file * * @param entry A wrapper that holds the information we need to get the file * @return The BaseFileTransferMappedRecord representing the file * @throws ResourceException failure to perform get */ protected BaseFileTransferMappedRecord getFile(ClientListEntry entry) throws ResourceException { if(logger.isDebugEnabled()) { // logger.debug("getFile called with: [" + entry + "]"); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Getting file [" + entry.getUri().getPath() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } try { return getClient().get(entry); } catch (ClientCommandGetException e) { logger.warn("Underlying File Transfer operation failed [GET]!", e); //$NON-NLS-1$ throw new ResourceException(e); } }