Skip to content

Commit 9faef2b

Browse files
author
Kincaid Savoie
committed
Made copy_file branching simpler; updated copy_file documentation.
1 parent a3ae185 commit 9faef2b

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

pssh/ssh_client.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -282,22 +282,23 @@ def copy_file(self, local_file, remote_file, recurse=False):
282282
:type local_file: str
283283
:param remote_file: Remote filepath on remote host to copy file to
284284
:type remote_file: str
285+
:param recurse: Whether or not to descend into directories recursively.
286+
:type recurse: bool
285287
"""
286-
if os.path.isfile(local_file) or not recurse:
287-
sftp = self._make_sftp()
288-
destination = [_dir for _dir in remote_file.split(os.path.sep)
289-
if _dir][:-1]
290-
if remote_file.startswith(os.path.sep):
291-
destination[0] = os.path.sep + destination[0]
292-
# import ipdb; ipdb.set_trace()
293-
try:
294-
sftp.stat(destination[0])
295-
except IOError:
296-
self.mkdir(sftp, destination[0])
297-
try:
298-
sftp.put(local_file, remote_file)
299-
except Exception, error:
300-
logger.error("Error occured copying file %s to remote destination %s:%s - %s",
301-
local_file, self.host, remote_file, error)
302-
else:
303-
self._copy_dir(local_file, remote_file)
288+
if os.path.isdir(local_file) and recurse:
289+
return self._copy_dir(local_file, remote_file)
290+
sftp = self._make_sftp()
291+
destination = [_dir for _dir in remote_file.split(os.path.sep)
292+
if _dir][:-1]
293+
if remote_file.startswith(os.path.sep):
294+
destination[0] = os.path.sep + destination[0]
295+
# import ipdb; ipdb.set_trace()
296+
try:
297+
sftp.stat(destination[0])
298+
except IOError:
299+
self.mkdir(sftp, destination[0])
300+
try:
301+
sftp.put(local_file, remote_file)
302+
except Exception, error:
303+
logger.error("Error occured copying file %s to remote destination %s:%s - %s",
304+
local_file, self.host, remote_file, error)

0 commit comments

Comments
 (0)