rdubois-mel commented on issue #4866:
URL: https://github.com/apache/hop/issues/4866#issuecomment-2894194446
I modified the following 2 functions in the
`plugins/actions/ftp/src/main/java/org/apache/hop/workflow/actions/ftp/ActionFtpDialog.java`
file to correctly test the authentication and the remote dir.
This seems to work well, it just needs a more human-friendly string to
correctly say that the remote dir does not exist.
```java
(...)
private void checkRemoteFolder(boolean ftpFolder, boolean checkMoveFolder,
String foldername) {
if (!Utils.isEmpty(foldername) && connectToFtp(ftpFolder,
checkMoveFolder)) {
try {
boolean exists = ftpclient.changeWorkingDirectory(foldername);
if (exists) {
MessageBox mb = new MessageBox(shell, SWT.OK |
SWT.ICON_INFORMATION);
mb.setMessage(
BaseMessages.getString(PKG, "ActionFtp.FolderExists.OK",
foldername) + Const.CR);
mb.setText(BaseMessages.getString(PKG,
"ActionFtp.FolderExists.Title.Ok"));
mb.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(
BaseMessages.getString(PKG, "ActionFtp.FolderExists.NOK",
foldername) + Const.CR);
mb.setText(BaseMessages.getString(PKG,
"ActionFtp.FolderExists.Title.Bad"));
mb.open();
}
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage("Error checking remote folder: " + e.getMessage());
mb.setText("Folder Check Failed");
mb.open();
}
}
}
private boolean connectToFtp(boolean checkFolder, boolean
checkMoveToFolder) {
try {
if (ftpclient == null || !ftpclient.isConnected()) {
ActionFtp actionFtp = new ActionFtp();
getInfo(actionFtp);
ftpclient =
FtpClientUtil.connectAndLogin(LogChannel.UI, variables,
actionFtp, wName.getText());
// Explicit authentication verification
try {
if (ftpclient == null || !ftpclient.isConnected()) {
throw new Exception("FTP client is null or not connected.");
}
// Attempting to list files to validate authentication
ftpclient.listFiles();
} catch (Exception authEx) {
throw new Exception("FTP authentication failed: " +
authEx.getMessage(), authEx);
}
}
return true;
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(
BaseMessages.getString(
PKG, "ActionFtp.ErrorConnect.NOK", wServerName.getText(),
e.getMessage()));
mb.setText(BaseMessages.getString(PKG,
"ActionFtp.ErrorConnect.Title.Bad"));
mb.open();
return false;
}
}
(...)
```
To summarize, I added the return value handling for remote directory changes.
And for authentication, I added a check (listFiles) because isConnected()
isn't sufficient.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]