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());
}
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;
}
Aggregations