From ebe2453446b55fe11b154ace45d95b605b9670ff Mon Sep 17 00:00:00 2001
From: Simon Tatham <anakin@pobox.com>
Date: Thu, 28 Nov 2024 21:20:23 +0000
Subject: [PATCH] psftp: use cmdline_arg_to_filename for batch files.

On Windows, this means they can use non-CP_ACP characters. Also it has
the side effect of cloning the filename out of the CmdlineArgList,
which makes it still valid after cmdline_arg_list_free (oops).
---
 psftp.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/psftp.c b/psftp.c
index 5afd5e54..69044694 100644
--- a/psftp.c
+++ b/psftp.c
@@ -2393,7 +2393,7 @@ static void do_sftp_cleanup(void)
     }
 }
 
-int do_sftp(int mode, int modeflags, const char *batchfile)
+int do_sftp(int mode, int modeflags, Filename *batchfile)
 {
     FILE *fp;
     int ret;
@@ -2417,9 +2417,9 @@ int do_sftp(int mode, int modeflags, const char *batchfile)
                 break;
         }
     } else {
-        fp = fopen(batchfile, "r");
+        fp = f_open(batchfile, "r", false);
         if (!fp) {
-            printf("Fatal: unable to open %s\n", batchfile);
+            printf("Fatal: unable to open %s\n", filename_to_str(batchfile));
             return 1;
         }
         ret = 0;
@@ -2800,7 +2800,7 @@ int psftp_main(CmdlineArgList *arglist)
     int mode = 0;
     int modeflags = 0;
     bool sanitise_stderr = true;
-    const char *batchfile = NULL;
+    Filename *batchfile = NULL;
 
     sk_init();
 
@@ -2845,7 +2845,7 @@ int psftp_main(CmdlineArgList *arglist)
             version();
         } else if (strcmp(argstr, "-b") == 0 && nextarg) {
             mode = 1;
-            batchfile = cmdline_arg_to_str(nextarg);
+            batchfile = cmdline_arg_to_filename(nextarg);
             arglistpos++;
         } else if (strcmp(argstr, "-bc") == 0) {
             modeflags = modeflags | 1;