Skip to content

Commit 5d202ca

Browse files
author
Dan
committed
Create all paths in remote directory - #64
1 parent 059cb62 commit 5d202ca

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pssh/ssh_client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ def mkdir(self, sftp, directory):
313313
parent_path = directory.split(os.path.sep, 1)[0]
314314
sub_dirs = None
315315
if not parent_path and directory.startswith(os.path.sep):
316-
parent_path, sub_dirs = sub_dirs.split(os.path.sep, 1)
316+
try:
317+
parent_path, sub_dirs = sub_dirs.split(os.path.sep, 1)
318+
except ValueError:
319+
return True
317320
try:
318321
sftp.stat(parent_path)
319322
except IOError:
@@ -348,22 +351,21 @@ def copy_file(self, local_file, remote_file, recurse=False):
348351
:raises: :mod:`ValueError` when a directory is supplied to local_file \
349352
and recurse is not set
350353
"""
354+
# import ipdb; ipdb.set_trace()
351355
if os.path.isdir(local_file) and recurse:
352356
return self._copy_dir(local_file, remote_file)
353357
elif os.path.isdir(local_file) and not recurse:
354358
raise ValueError("Recurse must be true if local_file is a "
355359
"directory.")
356360
sftp = self._make_sftp()
357361
try:
358-
destination = [_dir for _dir in remote_file.split(os.path.sep)
359-
if _dir][:-1][0]
362+
destination = os.path.sep.join([_dir for _dir in remote_file.split(os.path.sep)
363+
if _dir][:-1])
360364
except IndexError:
361365
destination = ''
362366
if remote_file.startswith(os.path.sep) or not destination:
363367
destination = os.path.sep + destination
364-
try:
365-
sftp.stat(destination)
366-
except IOError:
368+
if os.path.sep in remote_file:
367369
self.mkdir(sftp, destination)
368370
sftp.chdir()
369371
try:

0 commit comments

Comments
 (0)