Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/main/java/com/plugin/sshjplugin/SSHJFileCopierPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ private String copyFile(
StepFailureReason.ConfigurationFailure, e);
}

final SSHClient client = createSshClient();
scp.connect(client);

SSHClient client = null;
try {
client = createSshClient();
scp.connect(client);
Comment on lines +188 to +189
scp.execute(client);
} catch (Exception e) {
throw new FileCopierException("Configuration error: " + e.getMessage(),
Expand All @@ -200,13 +200,16 @@ private String copyFile(
);
}
}
}

try {
client.disconnect();
client.close();
} catch (IOException iex) {
throw new SSHJBuilder.BuilderException(iex);
if (null != client) {
try {
client.disconnect();
client.close();
} catch (IOException iex) {
// Log cleanup errors instead of throwing to avoid masking original exception
logger.log(Constants.WARN_LEVEL, "[sshj-scp] Error closing SSH connection: " +
iex.getMessage());
}
}
}

return remotefile;
Expand Down Expand Up @@ -237,21 +240,25 @@ private String[] copyMultipleFiles(
StepFailureReason.ConfigurationFailure, e);
}

final SSHClient client = createSshClient();
scp.connect(client);

SSHClient client = null;
try {
client = createSshClient();
scp.connect(client);
scp.execute(client);
} catch (Exception e) {
throw new FileCopierException("Configuration error: " + e.getMessage(),
StepFailureReason.ConfigurationFailure, e);
}

try {
client.disconnect();
client.close();
} catch (IOException iex) {
throw new SSHJBuilder.BuilderException(iex);
} finally {
if (null != client) {
try {
client.disconnect();
client.close();
} catch (IOException iex) {
// Log cleanup errors instead of throwing to avoid masking original exception
logger.log(Constants.WARN_LEVEL, "[sshj-scp] Error closing SSH connection: " +
iex.getMessage());
}
}
}

ArrayList<String> ret = new ArrayList<>();
Expand Down
Loading