Skip to content

Commit

Permalink
Merge pull request #87 from p0dalirius/fixed-get-put
Browse files Browse the repository at this point in the history
[bugfix] Fixed path handling error in get and put
  • Loading branch information
p0dalirius authored Jul 8, 2024
2 parents d4ced0f + 2848737 commit 0b83714
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions smbclientng/core/SMBSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0b83714

Please sign in to comment.