From 2848737d07f5c99d4b47e9da43e429c8c29ecb88 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:53:04 +0200 Subject: [PATCH] [bugfix] Fixed path handling error in get and put --- smbclientng/core/SMBSession.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/smbclientng/core/SMBSession.py b/smbclientng/core/SMBSession.py index 178bf31..ac2a90c 100644 --- a/smbclientng/core/SMBSession.py +++ b/smbclientng/core/SMBSession.py @@ -127,10 +127,12 @@ def init_smb_session(self): else: self.logger.error("Could not connect to '%s:%d'" % (self.host, int(self.port))) self.connected = False + self.smbClient = None except OSError as err: if self.config.debug: traceback.print_exc() self.logger.error("Could not connect to '%s:%d': %s" % (self.host, int(self.port), err)) + self.connected = False self.smbClient = None if self.smbClient is not None: @@ -279,7 +281,10 @@ def get_file(self, path=None, keepRemotePath=False, localDownloadDir="./"): # Parse path path = path.replace('/', ntpath.sep) if ntpath.sep in path: - tmp_search_path = ntpath.normpath(self.smb_cwd + ntpath.sep + ntpath.dirname(path)) + if path.startswith(ntpath.sep): + tmp_search_path = ntpath.normpath(ntpath.dirname(path)) + else: + tmp_search_path = ntpath.normpath(self.smb_cwd + ntpath.sep + ntpath.dirname(path)) else: tmp_search_path = ntpath.normpath(self.smb_cwd + ntpath.sep) # Parse filename @@ -840,7 +845,7 @@ def put_file(self, localpath=None): f = LocalFileIO( mode="rb", path=localpath, - debug=self.config.debug + logger=self.logger ) self.smbClient.putFile( shareName=self.smb_share,