receive-file: add --output-file to override local output filename

This commit is contained in:
Brian Warner 2015-03-16 00:18:53 -07:00
parent 5fd85fd884
commit 84aa7ff248
2 changed files with 16 additions and 10 deletions

View File

@ -44,7 +44,10 @@ def receive_file(so):
print("Receiving %d bytes for '%s' (%s).." % (filesize, filename, print("Receiving %d bytes for '%s' (%s).." % (filesize, filename,
transit_receiver.describe())) transit_receiver.describe()))
# only write to the current directory, and never overwrite anything 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()) here = os.path.abspath(os.getcwd())
target = os.path.abspath(os.path.join(here, filename)) target = os.path.abspath(os.path.join(here, filename))
if os.path.dirname(target) != here: if os.path.dirname(target) != here:
@ -79,7 +82,7 @@ def receive_file(so):
os.rename(tmp, target) 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.send_record("ok\n")
record_pipe.close() record_pipe.close()
return 0 return 0

View File

@ -17,6 +17,9 @@ class SendFileOptions(usage.Options):
synopsis = "FILENAME" synopsis = "FILENAME"
class ReceiveFileOptions(usage.Options): class ReceiveFileOptions(usage.Options):
optParameters = [
["output-file", "o", None, "File to create"],
]
def parseArgs(self, code=None): def parseArgs(self, code=None):
self["code"] = code self["code"] = code
synopsis = "[CODE]" synopsis = "[CODE]"