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