From d9c8b10c03512a1bea90b624d0b2f5ff0341ee03 Mon Sep 17 00:00:00 2001 From: Dan <22e889d8@opayq.com> Date: Thu, 10 Dec 2015 17:40:11 +0000 Subject: [PATCH] Fix copy file directory creation logic --- pssh/ssh_client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pssh/ssh_client.py b/pssh/ssh_client.py index f662a189..aa0a333a 100644 --- a/pssh/ssh_client.py +++ b/pssh/ssh_client.py @@ -318,9 +318,12 @@ def copy_file(self, local_file, remote_file, recurse=False): raise ValueError("Recurse must be true if local_file is a " "directory.") sftp = self._make_sftp() - destination = [_dir for _dir in remote_file.split(os.path.sep) - if _dir][:-1][0] - if remote_file.startswith(os.path.sep): + try: + destination = [_dir for _dir in remote_file.split(os.path.sep) + if _dir][:-1][0] + except IndexError: + destination = '' + if remote_file.startswith(os.path.sep) or not destination: destination = os.path.sep + destination try: sftp.stat(destination)