Search in sources :

Example 6 with SFTPClient

use of org.pentaho.di.job.entries.sftp.SFTPClient in project pentaho-kettle by pentaho.

the class JobEntryFTPDeleteDialog method connectToSFTP.

private boolean connectToSFTP() {
    boolean retval = false;
    try {
        if (sftpclient == null) {
            // Create sftp client to host ...
            sftpclient = new SFTPClient(InetAddress.getByName(jobMeta.environmentSubstitute(wServerName.getText())), Const.toInt(jobMeta.environmentSubstitute(wPort.getText()), 22), jobMeta.environmentSubstitute(wUserName.getText()));
            // login to ftp host ...
            sftpclient.login(Utils.resolvePassword(jobMeta, wPassword.getText()));
            pwdFolder = sftpclient.pwd();
        }
        retval = true;
    } catch (Exception e) {
        if (sftpclient != null) {
            try {
                sftpclient.disconnect();
            } catch (Exception ignored) {
            // We've tried quitting the SFTP Client exception
            // nothing else to be done if the SFTP Client was already disconnected
            }
            sftpclient = null;
        }
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobFTPDelete.ErrorConnect.NOK", e.getMessage()) + Const.CR);
        mb.setText(BaseMessages.getString(PKG, "JobFTPDelete.ErrorConnect.Title.Bad"));
        mb.open();
    }
    return retval;
}
Also used : SFTPClient(org.pentaho.di.job.entries.sftp.SFTPClient) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 7 with SFTPClient

use of org.pentaho.di.job.entries.sftp.SFTPClient in project pentaho-kettle by pentaho.

the class SFTPPutDialog method createSFTPClient.

SFTPClient createSFTPClient() throws UnknownHostException, KettleJobException {
    // Create sftp client to host ...
    sftpclient = new SFTPClient(InetAddress.getByName(transMeta.environmentSubstitute(wServerName.getText())), Const.toInt(transMeta.environmentSubstitute(wServerPort.getText()), 22), transMeta.environmentSubstitute(wUserName.getText()), transMeta.environmentSubstitute(wKeyFilename.getText()), transMeta.environmentSubstitute(wkeyfilePass.getText()));
    // Set proxy?
    String realProxyHost = transMeta.environmentSubstitute(wProxyHost.getText());
    if (!Utils.isEmpty(realProxyHost)) {
        // Set proxy
        sftpclient.setProxy(realProxyHost, transMeta.environmentSubstitute(wProxyPort.getText()), transMeta.environmentSubstitute(wProxyUsername.getText()), Utils.resolvePassword(transMeta, wProxyPassword.getText()), wProxyType.getText());
    }
    // login to ftp host ...
    sftpclient.login(Utils.resolvePassword(transMeta, wPassword.getText()));
    return sftpclient;
}
Also used : SFTPClient(org.pentaho.di.job.entries.sftp.SFTPClient)

Example 8 with SFTPClient

use of org.pentaho.di.job.entries.sftp.SFTPClient in project pentaho-kettle by pentaho.

the class SFTPPutDialogTest method connectToSFTP_CreateNewConnection_AfterChange.

@Test
public void connectToSFTP_CreateNewConnection_AfterChange() throws Exception {
    SFTPClient sftp = mock(SFTPClient.class);
    SFTPPutMeta sodMeta = new SFTPPutMeta();
    SFTPPutDialog sod = new SFTPPutDialog(mock(Shell.class), sodMeta, mock(TransMeta.class), "SFTPPutDialogTest");
    SFTPPutDialog sodSpy = spy(sod);
    doReturn(sftp).when(sodSpy).createSFTPClient();
    assertTrue(sodSpy.connectToSFTP(false, null));
    sodMeta.setChanged(true);
    assertTrue(sodSpy.connectToSFTP(false, null));
    verify(sodSpy, times(2)).createSFTPClient();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransMeta(org.pentaho.di.trans.TransMeta) SFTPClient(org.pentaho.di.job.entries.sftp.SFTPClient) SFTPPutMeta(org.pentaho.di.trans.steps.sftpput.SFTPPutMeta) Test(org.junit.Test)

Example 9 with SFTPClient

use of org.pentaho.di.job.entries.sftp.SFTPClient in project pentaho-kettle by pentaho.

the class JobEntrySFTPDialog method connectToSFTP.

private boolean connectToSFTP(boolean checkFolder, String Remotefoldername) {
    boolean retval = false;
    try {
        if (sftpclient == null) {
            // Create sftp client to host ...
            sftpclient = new SFTPClient(InetAddress.getByName(jobMeta.environmentSubstitute(wServerName.getText())), Const.toInt(jobMeta.environmentSubstitute(wServerPort.getText()), 22), jobMeta.environmentSubstitute(wUserName.getText()), jobMeta.environmentSubstitute(wKeyFilename.getText()), jobMeta.environmentSubstitute(wkeyfilePass.getText()));
            // Set proxy?
            String realProxyHost = jobMeta.environmentSubstitute(wProxyHost.getText());
            if (!Utils.isEmpty(realProxyHost)) {
                // Set proxy
                sftpclient.setProxy(realProxyHost, jobMeta.environmentSubstitute(wProxyPort.getText()), jobMeta.environmentSubstitute(wProxyUsername.getText()), Utils.resolvePassword(jobMeta, wProxyPassword.getText()), wProxyType.getText());
            }
            // login to ftp host ...
            sftpclient.login(jobEntry.getRealPassword(jobMeta.environmentSubstitute(wPassword.getText())));
            retval = true;
        }
        if (checkFolder) {
            retval = sftpclient.folderExists(Remotefoldername);
        }
    } catch (Exception e) {
        if (sftpclient != null) {
            try {
                sftpclient.disconnect();
            } catch (Exception ignored) {
            // We've tried quitting the SFTP Client exception
            // nothing else to be done if the SFTP Client was already disconnected
            }
            sftpclient = null;
        }
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobSFTP.ErrorConnect.NOK", wServerName.getText(), e.getMessage()) + Const.CR);
        mb.setText(BaseMessages.getString(PKG, "JobSFTP.ErrorConnect.Title.Bad"));
        mb.open();
    }
    return retval;
}
Also used : SFTPClient(org.pentaho.di.job.entries.sftp.SFTPClient) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

SFTPClient (org.pentaho.di.job.entries.sftp.SFTPClient)9 MessageBox (org.eclipse.swt.widgets.MessageBox)3 Shell (org.eclipse.swt.widgets.Shell)2 Test (org.junit.Test)2 TransMeta (org.pentaho.di.trans.TransMeta)2 SFTPPutMeta (org.pentaho.di.trans.steps.sftpput.SFTPPutMeta)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 FileObject (org.apache.commons.vfs2.FileObject)1 Before (org.junit.Before)1 Result (org.pentaho.di.core.Result)1 ResultFile (org.pentaho.di.core.ResultFile)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1