From c2e518ffebf404b97ba0f5a41c9b6add52be63c6 Mon Sep 17 00:00:00 2001 From: RichieHakim Date: Sun, 4 Feb 2024 22:50:30 -0500 Subject: [PATCH] Add mkdir parameter to put_dir method in sftp_interface class --- bnpm/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bnpm/server.py b/bnpm/server.py index 29fd81f..c0cc465 100644 --- a/bnpm/server.py +++ b/bnpm/server.py @@ -570,7 +570,7 @@ def connect( self.transport.connect(None, username, password) ## authorization self.sftp = paramiko.SFTPClient.from_transport(self.transport) ## open sftp - def put_dir(self, source, target, verbose=True): + def put_dir(self, source, target, mkdir=True, verbose=True): ''' Uploads the contents of the source directory to the target path. All subdirectories in source are created under target recusively. @@ -579,10 +579,15 @@ def put_dir(self, source, target, verbose=True): Path to the source directory (local). target (str): Path to the target directory (remote). + mkdir (bool): + Make the target directory if it does not exist. ''' source = Path(source).resolve() target = Path(target).resolve() + if mkdir: + self.mkdir_safe(str(target), ignore_existing=True) + for item in os.listdir(source): if os.path.isfile(source / item): if verbose: