Skip to content

Commit

Permalink
Create all paths in remote directory - #64
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Sep 7, 2016
1 parent 059cb62 commit 5d202ca
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pssh/ssh_client.py
Expand Up @@ -313,7 +313,10 @@ def mkdir(self, sftp, directory):
parent_path = directory.split(os.path.sep, 1)[0]
sub_dirs = None
if not parent_path and directory.startswith(os.path.sep):
parent_path, sub_dirs = sub_dirs.split(os.path.sep, 1)
try:
parent_path, sub_dirs = sub_dirs.split(os.path.sep, 1)
except ValueError:
return True
try:
sftp.stat(parent_path)
except IOError:
Expand Down Expand Up @@ -348,22 +351,21 @@ def copy_file(self, local_file, remote_file, recurse=False):
:raises: :mod:`ValueError` when a directory is supplied to local_file \
and recurse is not set
"""
# import ipdb; ipdb.set_trace()
if os.path.isdir(local_file) and recurse:
return self._copy_dir(local_file, remote_file)
elif os.path.isdir(local_file) and not recurse:
raise ValueError("Recurse must be true if local_file is a "
"directory.")
sftp = self._make_sftp()
try:
destination = [_dir for _dir in remote_file.split(os.path.sep)
if _dir][:-1][0]
destination = os.path.sep.join([_dir for _dir in remote_file.split(os.path.sep)
if _dir][:-1])
except IndexError:
destination = ''
if remote_file.startswith(os.path.sep) or not destination:
destination = os.path.sep + destination
try:
sftp.stat(destination)
except IOError:
if os.path.sep in remote_file:
self.mkdir(sftp, destination)
sftp.chdir()
try:
Expand Down

0 comments on commit 5d202ca

Please sign in to comment.