I've broken output to files that don't exist before running sshexec
diff --git a/WHATSNEW b/WHATSNEW
index ab9d210..1eaf764 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -8,6 +8,8 @@
    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 3a87879..1cd273b 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 @@
      */
     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) {