Search in sources :

Example 6 with FTPSConnection

use of org.pentaho.di.job.entries.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.

the class JobEntryFTPSPUTTest method testBinaryModeSetAfterConnectionSuccess.

/**
 * PDI-6868, attempt to set binary mode is after the connection.connect() succeeded.
 * @throws Exception
 */
@Test
public void testBinaryModeSetAfterConnectionSuccess() throws Exception {
    JobEntryFTPSPUT job = new JobEntryFTPSPUTCustom();
    FTPSConnection connection = Mockito.mock(FTPSConnection.class);
    InOrder inOrder = Mockito.inOrder(connection);
    job.buildFTPSConnection(connection);
    inOrder.verify(connection).connect();
    inOrder.verify(connection).setBinaryMode(Mockito.anyBoolean());
}
Also used : InOrder(org.mockito.InOrder) FTPSConnection(org.pentaho.di.job.entries.ftpsget.FTPSConnection) Test(org.junit.Test)

Example 7 with FTPSConnection

use of org.pentaho.di.job.entries.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.

the class JobEntryFTPSPUTDialog method connectToFTP.

private boolean connectToFTP(boolean checkfolder, String remoteFoldername) {
    String realServername = null;
    try {
        realServername = jobMeta.environmentSubstitute(wServerName.getText());
        int realPort = Const.toInt(jobMeta.environmentSubstitute(wServerPort.getText()), 0);
        String realUsername = jobMeta.environmentSubstitute(wUserName.getText());
        String realPassword = Utils.resolvePassword(jobMeta, wPassword.getText());
        if (connection == null) {
            // Create ftp client to host:port ...
            connection = new FTPSConnection(FTPSConnection.getConnectionTypeByDesc(wConnectionType.getText()), realServername, realPort, realUsername, realPassword);
            if (!Utils.isEmpty(wProxyHost.getText())) {
                // Set proxy
                String realProxy_host = jobMeta.environmentSubstitute(wProxyHost.getText());
                String realProxy_user = jobMeta.environmentSubstitute(wProxyUsername.getText());
                String realProxy_pass = Utils.resolvePassword(jobMeta, wProxyPassword.getText());
                connection.setProxyHost(realProxy_host);
                int proxyport = Const.toInt(jobMeta.environmentSubstitute(wProxyPort.getText()), 990);
                if (proxyport != 0) {
                    connection.setProxyPort(proxyport);
                }
                if (!Utils.isEmpty(realProxy_user)) {
                    connection.setProxyUser(realProxy_user);
                }
                if (!Utils.isEmpty(realProxy_pass)) {
                    connection.setProxyPassword(realProxy_pass);
                }
            }
            // login to FTPS host ...
            connection.connect();
        }
        if (checkfolder) {
            // move to spool dir ...
            if (!Utils.isEmpty(remoteFoldername)) {
                String realFtpDirectory = jobMeta.environmentSubstitute(remoteFoldername);
                return connection.isDirectoryExists(realFtpDirectory);
            }
        }
        return true;
    } catch (Exception e) {
        if (connection != null) {
            try {
                connection.disconnect();
            } catch (Exception ignored) {
            // We've tried quitting the FTPS Client exception
            // nothing else to be done if the FTPS Client was already disconnected
            }
            connection = null;
        }
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobFTPSPUT.ErrorConnect.NOK", realServername, e.getMessage()) + Const.CR);
        mb.setText(BaseMessages.getString(PKG, "JobFTPSPUT.ErrorConnect.Title.Bad"));
        mb.open();
    }
    return false;
}
Also used : FTPSConnection(org.pentaho.di.job.entries.ftpsget.FTPSConnection) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

FTPSConnection (org.pentaho.di.job.entries.ftpsget.FTPSConnection)7 MessageBox (org.eclipse.swt.widgets.MessageBox)3 File (java.io.File)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 Result (org.pentaho.di.core.Result)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