diff --git a/WHATSNEW b/WHATSNEW index ab9d21094..1eaf76437 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -8,6 +8,8 @@ Fixed bugs: the stacktrace for failures. This is now fixed. Bugzilla Report 63827 + * sshexec failed to write output to a file if the file didn't exist + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java index 3a8787903..1cd273b54 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java @@ -482,8 +482,10 @@ public class SSHExec extends SSHBase { */ private void writeToFile(final String from, final boolean append, final File to) throws IOException { + final StandardOpenOption appendOrTruncate = append ? StandardOpenOption.APPEND + : StandardOpenOption.TRUNCATE_EXISTING; try (BufferedWriter out = Files.newBufferedWriter(to.getAbsoluteFile().toPath(), - StandardOpenOption.APPEND)) { + appendOrTruncate, StandardOpenOption.CREATE)) { final StringReader in = new StringReader(from); final char[] buffer = new char[BUFFER_SIZE]; while (true) {