public File getDir( String dirname ) throws KettleJobException { File fl = new File( dirname ); if ( !fl.isDirectory() ) { throw new KettleJobException( "'" + dirname + "' is not a directory" ); } return fl; }
public void put( InputStream inputStream, String remoteFile ) throws KettleJobException { int mode = ChannelSftp.OVERWRITE; try { c.put( inputStream, remoteFile, null, mode ); } catch ( Exception e ) { throw new KettleJobException( e ); } finally { if ( inputStream != null ) { try { inputStream.close(); } catch ( IOException e ) { throw new KettleJobException( e ); } } } }
public void chdir( String dirToChangeTo ) throws KettleJobException { try { c.cd( dirToChangeTo.replace( "\\\\", "/" ). replace( "\\", "/" ) ); } catch ( SftpException e ) { throw new KettleJobException( e ); } }
public String pwd() throws KettleJobException { try { return c.pwd(); } catch ( SftpException e ) { throw new KettleJobException( e ); } }
public void delete( String file ) throws KettleJobException { try { c.rm( file ); } catch ( SftpException e ) { throw new KettleJobException( e ); } }
/** * Rename the file. */ public void renameFile( String sourcefilename, String destinationfilename ) throws KettleJobException { try { c.rename( sourcefilename, destinationfilename ); } catch ( SftpException e ) { throw new KettleJobException( e ); } }
/** * @deprecated use {@link #get(FileObject, String)} * @param localFilePath * @param remoteFile * @throws KettleJobException */ @Deprecated public void get( String localFilePath, String remoteFile ) throws KettleJobException { int mode = ChannelSftp.OVERWRITE; try { c.get( remoteFile, localFilePath, null, mode ); } catch ( SftpException e ) { throw new KettleJobException( e ); } }
public void get( FileObject localFile, String remoteFile ) throws KettleJobException { OutputStream localStream = null; try { localStream = KettleVFS.getOutputStream( localFile, false ); c.get( remoteFile, localStream ); } catch ( SftpException e ) { throw new KettleJobException( e ); } catch ( IOException e ) { throw new KettleJobException( e ); } finally { if ( localStream != null ) { try { localStream.close(); } catch ( IOException ignore ) { // Ignore any IOException, as we're trying to close the stream anyways } } } }
public void put( FileObject fileObject, String remoteFile ) throws KettleJobException { int mode = ChannelSftp.OVERWRITE; InputStream inputStream = null; try { inputStream = KettleVFS.getInputStream( fileObject ); c.put( inputStream, remoteFile, null, mode ); } catch ( Exception e ) { throw new KettleJobException( e ); } finally { if ( inputStream != null ) { try { inputStream.close(); } catch ( IOException e ) { throw new KettleJobException( e ); } } } }
/** * Creates the given folder. The {@param path} can be either absolute or relative. * Allows creation of nested folders. */ public void createFolder( String path ) throws KettleJobException { try { String[] folders = path.split( "/" ); folders[ 0 ] = ( path.charAt( 0 ) != '/' ? pwd() + "/" : "" ) + folders[ 0 ]; for ( int i = 1; i < folders.length; i++ ) { folders[ i ] = folders[ i - 1 ] + "/" + folders[ i ]; } for ( String f : folders ) { if ( f.length() != 0 && !folderExists( f ) ) { c.mkdir( f ); } } } catch ( ArrayIndexOutOfBoundsException e ) { throw new KettleJobException( e ); } catch ( SftpException e ) { throw new KettleJobException( e ); } }
public FileType getFileType( String filename ) throws KettleJobException { try { SftpATTRS attrs = c.stat( filename ); if ( attrs == null ) { return FileType.IMAGINARY; } if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) { throw new KettleJobException( "Unknown permissions error" ); } if ( attrs.isDir() ) { return FileType.FOLDER; } else { return FileType.FILE; } } catch ( Exception e ) { throw new KettleJobException( e ); } }
public String[] dir() throws KettleJobException { String[] fileList = null; try { java.util.Vector<?> v = c.ls( "." ); java.util.Vector<String> o = new java.util.Vector<String>(); if ( v != null ) { for ( int i = 0; i < v.size(); i++ ) { Object obj = v.elementAt( i ); if ( obj != null && obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry ) { LsEntry lse = (com.jcraft.jsch.ChannelSftp.LsEntry) obj; if ( !lse.getAttrs().isDir() ) { o.add( lse.getFilename() ); } } } } if ( o.size() > 0 ) { fileList = new String[o.size()]; o.copyInto( fileList ); } } catch ( SftpException e ) { throw new KettleJobException( e ); } return fileList; }
public void login( String password ) throws KettleJobException { this.password = password; s.setPassword( this.getPassword() ); try { java.util.Properties config = new java.util.Properties(); config.put( "StrictHostKeyChecking", "no" ); // set compression property // zlib, none String compress = getCompression(); if ( compress != null ) { config.put( COMPRESSION_S2C, compress ); config.put( COMPRESSION_C2S, compress ); } s.setConfig( config ); s.connect(); Channel channel = s.openChannel( "sftp" ); channel.connect(); c = (ChannelSftp) channel; } catch ( JSchException e ) { throw new KettleJobException( e ); } }
throw new KettleJobException( "For a SFTP connection server name and username must be set and server port must be greater than zero." ); s.setConfig( PREFERRED_AUTH_CONFIG_NAME, getPreferredAuthentications() ); } catch ( IOException e ) { throw new KettleJobException( e ); } catch ( KettleFileException e ) { throw new KettleJobException( e ); } catch ( JSchException e ) { throw new KettleJobException( e );
public boolean folderExists( String foldername ) { boolean retval = false; try { SftpATTRS attrs = c.stat( foldername ); if ( attrs == null ) { return false; } if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 ) { throw new KettleJobException( "Unknown permissions error" ); } retval = attrs.isDir(); } catch ( Exception e ) { // Folder can not be found! } return retval; }
throw new KettleJobException( e ); // In case something else goes wrong.
public void setProxy( String host, String port, String user, String pass, String proxyType ) throws KettleJobException { if ( Utils.isEmpty( host ) || Const.toInt( port, 0 ) == 0 ) { throw new KettleJobException( "Proxy server name must be set and server port must be greater than zero." ); } Proxy proxy = null; String proxyhost = host + ":" + port; if ( proxyType.equals( PROXY_TYPE_HTTP ) ) { proxy = new ProxyHTTP( proxyhost ); if ( !Utils.isEmpty( user ) ) { ( (ProxyHTTP) proxy ).setUserPasswd( user, pass ); } } else if ( proxyType.equals( PROXY_TYPE_SOCKS5 ) ) { proxy = new ProxySOCKS5( proxyhost ); if ( !Utils.isEmpty( user ) ) { ( (ProxySOCKS5) proxy ).setUserPasswd( user, pass ); } } s.setProxy( proxy ); }
public Result execute( Result previousResult, int nr ) throws KettleJobException { Result result = previousResult; if ( isStart() ) { try { long sleepTime = getNextExecutionTime(); if ( sleepTime > 0 ) { parentJob.getLogChannel().logBasic( parentJob.getJobname(), "Sleeping: " + ( sleepTime / 1000 / 60 ) + " minutes (sleep time=" + sleepTime + ")" ); long totalSleep = 0L; while ( totalSleep < sleepTime && !parentJob.isStopped() ) { Thread.sleep( 1000L ); totalSleep += 1000L; } } } catch ( InterruptedException e ) { throw new KettleJobException( e ); } result = previousResult; result.setResult( true ); } else if ( isDummy() ) { result = previousResult; } return result; }
private void isFileOpenedInFolder( String path ) throws KettleException { List<TransMeta> openedTransFiles = getSpoon().delegates.trans.getTransformationList(); for ( TransMeta t : openedTransFiles ) { if ( t.getRepositoryDirectory().getPath() != null && ( t.getRepositoryDirectory().getPath() + "/" ).startsWith( path + "/" ) ) { throw new KettleTransException(); } } List<JobMeta> openedJobFiles = getSpoon().delegates.jobs.getJobList(); for ( JobMeta j : openedJobFiles ) { if ( j.getRepositoryDirectory().getPath() != null && ( j.getRepositoryDirectory().getPath() + "/" ).startsWith( path + "/" ) ) { throw new KettleJobException(); } } }
throw new KettleJobException( BaseMessages.getString( PKG, "JobEntrySetVariables.Error.UnableSetVariableCurrentJob", varname ) ); gpJob.setVariable( varname, value ); } else { throw new KettleJobException( BaseMessages.getString( PKG, "JobEntrySetVariables.Error.UnableSetVariableParentJob", varname ) ); throw new KettleJobException( BaseMessages.getString( PKG, "JobEntrySetVariables.Error.UnableSetVariableCurrentJob", varname ) );