@@ -304,22 +304,23 @@ def copy_file(self, local_file, remote_file, recurse=False):
304304 :type local_file: str
305305 :param remote_file: Remote filepath on remote host to copy file to
306306 :type remote_file: str
307+ :param recurse: Whether or not to descend into directories recursively.
308+ :type recurse: bool
307309 """
308- if os .path .isfile (local_file ) or not recurse :
309- sftp = self ._make_sftp ()
310- destination = [_dir for _dir in remote_file .split (os .path .sep )
311- if _dir ][:- 1 ][0 ]
312- if remote_file .startswith (os .path .sep ):
313- destination = os .path .sep + destination
314- try :
315- sftp .stat (destination [0 ])
316- except IOError :
317- self .mkdir (sftp , destination )
318- sftp .chdir ()
319- try :
320- sftp .put (local_file , remote_file )
321- except Exception , error :
322- logger .error ("Error occured copying file %s to remote destination %s:%s - %s" ,
323- local_file , self .host , remote_file , error )
324- else :
325- self ._copy_dir (local_file , remote_file )
310+ if os .path .isdir (local_file ) and recurse :
311+ return self ._copy_dir (local_file , remote_file )
312+ sftp = self ._make_sftp ()
313+ destination = [_dir for _dir in remote_file .split (os .path .sep )
314+ if _dir ][:- 1 ]
315+ if remote_file .startswith (os .path .sep ):
316+ destination [0 ] = os .path .sep + destination [0 ]
317+ # import ipdb; ipdb.set_trace()
318+ try :
319+ sftp .stat (destination [0 ])
320+ except IOError :
321+ self .mkdir (sftp , destination [0 ])
322+ try :
323+ sftp .put (local_file , remote_file )
324+ except Exception , error :
325+ logger .error ("Error occured copying file %s to remote destination %s:%s - %s" ,
326+ local_file , self .host , remote_file , error )
0 commit comments