use of org.pentaho.di.job.entries.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.
the class JobEntryFTPDeleteDialog method connectToFTPS.
private boolean connectToFTPS() {
boolean retval = false;
try {
if (ftpsclient == null) {
String realServername = jobMeta.environmentSubstitute(wServerName.getText());
String realUsername = jobMeta.environmentSubstitute(wUserName.getText());
String realPassword = Utils.resolvePassword(jobMeta, wPassword.getText());
int port = Const.toInt(jobMeta.environmentSubstitute(wPort.getText()), 0);
// Create ftp client to host:port ...
ftpsclient = new FTPSConnection(FTPSConnection.getConnectionTypeByDesc(wConnectionType.getText()), realServername, port, 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());
ftpsclient.setProxyHost(realProxy_host);
int proxyport = Const.toInt(jobMeta.environmentSubstitute(wProxyPort.getText()), 990);
if (proxyport != 0) {
ftpsclient.setProxyPort(proxyport);
}
if (!Utils.isEmpty(realProxy_user)) {
ftpsclient.setProxyUser(realProxy_user);
}
if (!Utils.isEmpty(realProxy_pass)) {
ftpsclient.setProxyPassword(realProxy_pass);
}
}
// login to FTPS host ...
ftpsclient.connect();
pwdFolder = ftpsclient.getWorkingDirectory();
}
retval = true;
} catch (Exception e) {
if (ftpsclient != null) {
try {
ftpsclient.disconnect();
} catch (Exception ignored) {
// We've tried quitting the FTPS Client exception
// nothing else to be done if the FTPS Client was already disconnected
}
ftpsclient = 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.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.
the class JobEntryFTPSGetDialog method connectToFTPS.
private boolean connectToFTPS(boolean checkfolder, boolean checkmoveToFolder) {
boolean retval = true;
String realServername = null;
try {
if (connection == null) {
// Create FTPS client to host:port ...
realServername = jobMeta.environmentSubstitute(wServerName.getText());
int port = Const.toInt(jobMeta.environmentSubstitute(wPort.getText()), 0);
String realUsername = jobMeta.environmentSubstitute(wUserName.getText());
String realPassword = Utils.resolvePassword(jobMeta, wPassword.getText());
connection = new FTPSConnection(FTPSConnection.getConnectionTypeByDesc(wConnectionType.getText()), realServername, port, 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();
// pwdFolder=connection.getWorkingDirectory();
}
String realFTPSDirectory = null;
if (!Utils.isEmpty(wFTPSDirectory.getText())) {
realFTPSDirectory = jobMeta.environmentSubstitute(wFTPSDirectory.getText());
}
if (checkfolder) {
// move to spool dir ...
if (!Utils.isEmpty(realFTPSDirectory)) {
// connection.changeDirectory(realFTPSDirectory);
retval = connection.isDirectoryExists(realFTPSDirectory);
}
}
if (checkmoveToFolder) {
if (!Utils.isEmpty(wMoveToDirectory.getText())) {
String realMoveDirectory = jobMeta.environmentSubstitute(wMoveToDirectory.getText());
// realMoveDirectory=realFTPSDirectory+"/"+realMoveDirectory;
// connection.changeDirectory(realMoveDirectory);
retval = connection.isDirectoryExists(realMoveDirectory);
}
}
} catch (Exception e) {
retval = false;
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, "JobFTPS.ErrorConnect.NOK", realServername, e.getMessage()) + Const.CR);
mb.setText(BaseMessages.getString(PKG, "JobFTPS.ErrorConnect.Title.Bad"));
mb.open();
}
return retval;
}
use of org.pentaho.di.job.entries.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.
the class JobEntryFTPDelete method FTPSConnect.
private void FTPSConnect(String realservername, String realusername, int realport, String realpassword, String realFTPDirectory, int realtimeout) throws Exception {
// Create ftps client to host ...
ftpsclient = new FTPSConnection(getFTPSConnectionType(), realservername, realport, realusername, realpassword);
if (!Utils.isEmpty(proxyHost)) {
String realProxy_host = environmentSubstitute(proxyHost);
String realProxy_username = environmentSubstitute(proxyUsername);
String realProxy_password = Utils.resolvePassword(this, proxyPassword);
ftpsclient.setProxyHost(realProxy_host);
if (!Utils.isEmpty(realProxy_username)) {
ftpsclient.setProxyUser(realProxy_username);
}
if (!Utils.isEmpty(realProxy_password)) {
ftpsclient.setProxyPassword(realProxy_password);
}
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryFTPDelete.OpenedProxyConnectionOn", realProxy_host));
}
int proxyport = Const.toInt(environmentSubstitute(proxyPort), 21);
if (proxyport != 0) {
ftpsclient.setProxyPort(proxyport);
}
} else {
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryFTPDelete.OpenedConnectionTo", realservername));
}
}
// set activeConnection connectmode ...
if (activeConnection) {
ftpsclient.setPassiveMode(false);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryFTPDelete.SetActive"));
}
} else {
ftpsclient.setPassiveMode(true);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryFTPDelete.SetPassive"));
}
}
// Set the timeout
ftpsclient.setTimeOut(realtimeout);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryFTPDelete.SetTimeout", String.valueOf(realtimeout)));
}
// now connect
ftpsclient.connect();
// move to spool dir ...
if (!Utils.isEmpty(realFTPDirectory)) {
ftpsclient.changeDirectory(realFTPDirectory);
if (isDetailed()) {
logDetailed("Changed to directory [" + realFTPDirectory + "]");
}
}
}
use of org.pentaho.di.job.entries.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.
the class JobEntryFTPSPUT method execute.
public Result execute(Result previousResult, int nr) {
Result result = previousResult;
result.setResult(false);
long filesput = 0;
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobFTPSPUT.Log.Starting"));
}
// String substitution..
String realServerName = environmentSubstitute(serverName);
String realServerPort = environmentSubstitute(serverPort);
String realUsername = environmentSubstitute(userName);
String realPassword = Encr.decryptPasswordOptionallyEncrypted(environmentSubstitute(password));
String realRemoteDirectory = environmentSubstitute(remoteDirectory);
String realWildcard = environmentSubstitute(wildcard);
String realLocalDirectory = environmentSubstitute(localDirectory);
FTPSConnection connection = null;
try {
// Create FTPS client to host:port ...
int realPort = Const.toInt(environmentSubstitute(realServerPort), 0);
// Define a new connection
connection = new FTPSConnection(getConnectionType(), realServerName, realPort, realUsername, realPassword);
this.buildFTPSConnection(connection);
// move to spool dir ...
if (!Utils.isEmpty(realRemoteDirectory)) {
connection.changeDirectory(realRemoteDirectory);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobFTPSPUT.Log.ChangedDirectory", realRemoteDirectory));
}
}
realRemoteDirectory = Const.NVL(realRemoteDirectory, FTPSConnection.HOME_FOLDER);
ArrayList<String> myFileList = new ArrayList<String>();
File localFiles = new File(realLocalDirectory);
if (!localFiles.exists()) {
// if local directory uses ${ signature this will be fail to MessageFormat.format ...
String error = BaseMessages.getString(PKG, "JobFTPSPUT.LocalFileDirectoryNotExists") + realLocalDirectory;
throw new Exception(error);
}
File[] children = localFiles.listFiles();
for (int i = 0; i < children.length; i++) {
// Get filename of file or directory
if (!children[i].isDirectory()) {
myFileList.add(children[i].getName());
}
}
String[] filelist = new String[myFileList.size()];
myFileList.toArray(filelist);
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobFTPSPUT.Log.FoundFileLocalDirectory", filelist.length, realLocalDirectory));
}
Pattern pattern = null;
if (!Utils.isEmpty(realWildcard)) {
pattern = Pattern.compile(realWildcard);
}
// Get the files in the list and execute put each file in the FTP
for (int i = 0; i < filelist.length && !parentJob.isStopped(); i++) {
boolean getIt = true;
// First see if the file matches the regular expression!
if (pattern != null) {
Matcher matcher = pattern.matcher(filelist[i]);
getIt = matcher.matches();
}
if (getIt) {
// File exists?
boolean fileExist = connection.isFileExists(filelist[i]);
if (isDebug()) {
if (fileExist) {
logDebug(BaseMessages.getString(PKG, "JobFTPSPUT.Log.FileExists", filelist[i]));
} else {
logDebug(BaseMessages.getString(PKG, "JobFTPSPUT.Log.FileDoesNotExists", filelist[i]));
}
}
if (!fileExist || (!onlyPuttingNewFiles && fileExist)) {
String localFilename = realLocalDirectory + Const.FILE_SEPARATOR + filelist[i];
if (isDebug()) {
logDebug(BaseMessages.getString(PKG, "JobFTPSPUT.Log.PuttingFileToRemoteDirectory", localFilename, realRemoteDirectory));
}
connection.uploadFile(localFilename, filelist[i]);
filesput++;
// Delete the file if this is needed!
if (remove) {
new File(localFilename).delete();
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobFTPSPUT.Log.DeletedFile", localFilename));
}
}
}
}
}
result.setResult(true);
result.setNrLinesOutput(filesput);
if (isDetailed()) {
logDebug(BaseMessages.getString(PKG, "JobFTPSPUT.Log.WeHavePut", filesput));
}
} catch (Exception e) {
result.setNrErrors(1);
logError(BaseMessages.getString(PKG, "JobFTPSPUT.Log.ErrorPuttingFiles", e.getMessage()));
logError(Const.getStackTracker(e));
} finally {
if (connection != null) {
try {
connection.disconnect();
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobFTPSPUT.Log.ErrorQuitingFTP", e.getMessage()));
}
}
}
return result;
}
use of org.pentaho.di.job.entries.ftpsget.FTPSConnection in project pentaho-kettle by pentaho.
the class JobEntryFTPPUTIT method prepareResources.
@Before
public void prepareResources() throws Exception {
connection = new FTPSConnection(CONNECTION_TYPE_FTP, "localhost", DEFAULT_PORT, ADMIN, PASSWORD);
connection.connect();
tempFile = new File(folder.getRoot(), UUID.randomUUID().toString());
tempFile.createNewFile();
entry = new JobEntryFTPPUT();
entry.setUserName(ADMIN);
entry.setPassword(PASSWORD);
entry.setServerName("localhost");
entry.setServerPort(Integer.toString(DEFAULT_PORT));
entry.setActiveConnection(true);
entry.setControlEncoding("UTF-8");
entry.setBinaryMode(true);
// tempFile is a UUID ==> it is a valid wildcard to itself (no need to escape)
entry.setWildcard(tempFile.getName());
}
Aggregations