diff --git a/src/wormhole/scripts/cmd_receive_file.py b/src/wormhole/scripts/cmd_receive_file.py index 4411fc5..97d0cc7 100644 --- a/src/wormhole/scripts/cmd_receive_file.py +++ b/src/wormhole/scripts/cmd_receive_file.py @@ -44,15 +44,18 @@ def receive_file(so): print("Receiving %d bytes for '%s' (%s).." % (filesize, filename, transit_receiver.describe())) - # only write to the current directory, and never overwrite anything - here = os.path.abspath(os.getcwd()) - target = os.path.abspath(os.path.join(here, filename)) - if os.path.dirname(target) != here: - print("Error: suggested filename (%s) would be outside current directory" - % (filename,)) - record_pipe.send_record("bad filename\n") - record_pipe.close() - return 1 + target = so["output-file"] + if not target: + # allow the sender to specify the filename, but only write to the + # current directory, and never overwrite anything + here = os.path.abspath(os.getcwd()) + target = os.path.abspath(os.path.join(here, filename)) + if os.path.dirname(target) != here: + print("Error: suggested filename (%s) would be outside current directory" + % (filename,)) + record_pipe.send_record("bad filename\n") + record_pipe.close() + return 1 if os.path.exists(target): print("Error: refusing to overwrite existing file %s" % (filename,)) record_pipe.send_record("file already exists\n") @@ -79,7 +82,7 @@ def receive_file(so): os.rename(tmp, target) - print("Received file written to %s" % filename) + print("Received file written to %s" % target) record_pipe.send_record("ok\n") record_pipe.close() return 0 diff --git a/src/wormhole/scripts/runner.py b/src/wormhole/scripts/runner.py index 7143e99..3b39cc7 100644 --- a/src/wormhole/scripts/runner.py +++ b/src/wormhole/scripts/runner.py @@ -17,6 +17,9 @@ class SendFileOptions(usage.Options): synopsis = "FILENAME" class ReceiveFileOptions(usage.Options): + optParameters = [ + ["output-file", "o", None, "File to create"], + ] def parseArgs(self, code=None): self["code"] = code synopsis = "[CODE]"