@Override public void run() { String sourceUrl = "NOT YET DEFINED"; String destUrl = "NOT YET DEFINED"; try { sourceUrl = source.getURL().toString(); destUrl = dest.getURL().toString(); logger.debug("Copying files from " + source + " to " + dest); dest.copyFrom(source, fileSelector); logger.debug("Finished copying files from " + source + " to " + dest); } catch (FileSystemException e) { logger.error("An error occured while copying files from " + source + " to " + dest, e); if (jobId != null) { logger.info( "Job " + jobId + " will be removed from the known job list. The system will not attempt again to retrieve data for this job. You could try to manually copy the data from the location " + sourceUrl); for (ISchedulerEventListenerExtended l : eventListeners) { l.pullDataFailed(jobId, sourceUrl, e); } removeAwaitedJob(jobId); return; } } // catch removeAwaitedJob(jobId); // delete source data String url = "NOT YET DEFINED"; for (FileObject fo : foldersToDelete) { try { url = fo.getURL().toString(); fo.delete(Selectors.SELECT_ALL); fo.delete(); } catch (FileSystemException e) { logger.warn( "Could not delete temporary fioles at location " + url + " . although the copy of these files to " + destUrl + " has been successffully performed."); } } for (ISchedulerEventListenerExtended l : eventListeners) { l.pullDataFinished(jobId, destUrl); } }
public boolean deleteFile(ServerDetailsDTO conDetails, String filePath) throws IOException { FileObject fileObject = null; StandardFileSystemManager manager = null; try { manager = new StandardFileSystemManager(); manager.init(); UserAuthenticator auth = new StaticUserAuthenticator(null, conDetails.getUserName(), conDetails.getPassword()); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); String fileUri = buildUri(conDetails, filePath); fileObject = manager.resolveFile(fileUri, opts); return fileObject.delete(); } finally { try { if (fileObject != null) { ((SftpFileSystem) fileObject.getFileSystem()).closeCommunicationLink(); FileSystem fs = null; fs = fileObject.getFileSystem(); manager.closeFileSystem(fs); } } finally { } } }
/** Does an 'rm' command. */ private void rm(final String[] cmd) throws Exception { if (cmd.length < 2) { throw new Exception("USAGE: rm <path>"); } final FileObject file = mgr.resolveFile(cwd, cmd[1]); file.delete(Selectors.SELECT_SELF); }
private boolean deleteOrMoveFiles(FileObject file, String destinationFolder) throws KettleException { try { boolean retval = false; // Delete the file if this is needed! // if (afterFtpPut.equals("delete_file")) { file.delete(); retval = true; if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobSSH2PUT.Log.DeletedFile", file.toString())); } } else if (afterFtpPut.equals("move_file")) { // Move File FileObject destination = null; FileObject source = null; try { destination = KettleVFS.getFileObject( destinationFolder + Const.FILE_SEPARATOR + file.getName().getBaseName(), this); file.moveTo(destination); retval = true; } catch (Exception e) { logError( BaseMessages.getString( PKG, "JobSSH2PUT.Cant_Move_File.Label", file.toString(), destinationFolder, e.getMessage())); } finally { if (destination != null) { try { destination.close(); } catch (Exception ex) { /* Ignore */ } } if (source != null) { try { source.close(); } catch (Exception ex) { /* Ignore */ } } } if (log.isDetailed()) { logDetailed( BaseMessages.getString( PKG, "JobSSH2PUT.Log.MovedFile", file.toString(), ftpDirectory)); } } return retval; } catch (Exception e) { throw new KettleException(e); } }
public void dispose(StepMetaInterface smi, StepDataInterface sdi) { meta = (GPLoadMeta) smi; data = (GPLoadData) sdi; super.dispose(smi, sdi); if (!preview && meta.isEraseFiles()) { // Erase the created cfg/dat files if requested. We don't erase // the rest of the files because it would be "stupid" to erase them // right after creation. If you don't want them, don't fill them in. FileObject fileObject = null; String method = meta.getLoadMethod(); if ( // GPLoadMeta.METHOD_AUTO_CONCURRENT.equals(method) || GPLoadMeta.METHOD_AUTO_END.equals(method)) { /* if ( meta.getControlFile() != null ) { try { fileObject = KettleVFS.getFileObject(environmentSubstitute(meta.getControlFile()), getTransMeta()); fileObject.delete(); fileObject.close(); } catch ( Exception ex ) { logError("Error deleting control file \'" + KettleVFS.getFilename(fileObject) + "\': " + ex.getMessage()); } }*/ } if (GPLoadMeta.METHOD_AUTO_END.equals(method)) { // In concurrent mode the data is written to the control file. if (meta.getDataFile() != null) { try { fileObject = KettleVFS.getFileObject(environmentSubstitute(meta.getDataFile()), getTransMeta()); fileObject.delete(); fileObject.close(); } catch (Exception ex) { logError( "Error deleting data file \'" + KettleVFS.getFilename(fileObject) + "\': " + ex.getMessage(), ex); } } } if (GPLoadMeta.METHOD_MANUAL.equals(method)) { logBasic("Deletion of files is not compatible with \'manual load method\'"); } } }
@Override public boolean backupAgentConfigurations(boolean remove) { try { super.backupAgentConfigurations(remove); // backup jaas.conf FileObject jaasConfigFile = targetConfDir.resolveFile("jaas.conf"); if (jaasConfigFile.exists()) { // backup file in the same folder it is installed backupFile(jaasConfigFile, jaasConfigFile.getParent()); if (remove) { jaasConfigFile.delete(); } } // backup setenv.sh and setenv.bat FileObject[] libs = targetBinDir.getChildren(); for (int i = 0; i < libs.length; i++) { FileObject cfgFile = libs[i]; if (!cfgFile.getType().getName().equals(FileType.FILE.getName())) { // ignore folders continue; } if (cfgFile.getName().getBaseName().startsWith("setenv") && (cfgFile.getName().getBaseName().endsWith(".sh") || cfgFile.getName().getBaseName().endsWith(".bat"))) { // backup files in the same folder they're installed in backupFile(cfgFile, cfgFile.getParent()); if (remove) { cfgFile.delete(); } } } } catch (Exception e) { getPrinter().printErrStatus("BackupAgentConfigurations", e.getMessage()); return false; } return true; }
@Override public boolean backupAgentConfigurations(boolean remove) { try { // backup portal-ext.properties FileObject portalConfFile = targetConfDir.resolveFile("portal-ext.properties"); if (portalConfFile.exists()) { // backup file in the same folder it is installed backupFile(portalConfFile, portalConfFile.getParent()); if (remove) { portalConfFile.delete(); } } } catch (Exception e) { getPrinter().printErrStatus("BackupAgentConfigurations", e.getMessage()); return false; } return true; }
public boolean writeFile(ServerDetailsDTO conDetails, String filePath, byte[] fileContent) throws IOException { FileObject fileObject2 = null; FileObject fileObject = null; StandardFileSystemManager manager = null; try { manager = new StandardFileSystemManager(); manager.init(); UserAuthenticator auth = new StaticUserAuthenticator(null, conDetails.getUserName(), conDetails.getPassword()); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); String fileUri = buildUri(conDetails, filePath); fileObject = manager.resolveFile(fileUri + ".tmp", opts); OutputStream os = fileObject.getContent().getOutputStream(); int size = fileContent.length; try { for (int index = 0; index < fileContent.length; index += 4000, size -= 4000) { os.write(fileContent, index, size > 4000 ? 4000 : size); if (Thread.currentThread().isInterrupted()) { fileObject.getContent().close(); fileObject.delete(); return false; } } os.flush(); } finally { fileObject.getContent().close(); } fileObject2 = manager.resolveFile(fileUri, opts); fileObject.moveTo(fileObject2); ((SftpFileSystem) fileObject2.getFileSystem()).closeCommunicationLink(); ((SftpFileSystem) fileObject.getFileSystem()).closeCommunicationLink(); } catch (IOException e) { throw e; } finally { try { FileSystem fs = null; if (fileObject2 != null) { fs = fileObject2.getFileSystem(); manager.closeFileSystem(fs); } fs = null; if (fileObject != null) { fs = fileObject.getFileSystem(); manager.closeFileSystem(fs); } } finally { // Just ignore the exception } } return true; }
protected void tearDown() throws Exception { if (rootDir != null) { rootDir.delete(new AllFileSelector()); } }