@@ -327,39 +327,41 @@ def mkdir(self, sftp, directory):
327
327
return self .mkdir (sftp , sub_dirs )
328
328
return True
329
329
330
- def _copy_dir (self , local_dir , remote_dir ):
330
+ def _copy_dir (self , local_dir , remote_dir , sftp ):
331
331
"""Call copy_file on every file in the specified directory, copying
332
332
them to the specified remote directory."""
333
333
file_list = os .listdir (local_dir )
334
334
for file_name in file_list :
335
335
local_path = os .path .join (local_dir , file_name )
336
336
remote_path = os .path .join (remote_dir , file_name )
337
- self .copy_file (local_path , remote_path , recurse = True )
337
+ self .copy_file (local_path , remote_path , recurse = True ,
338
+ sftp = sftp )
338
339
339
- def copy_file (self , local_file , remote_file , recurse = False ):
340
+ def copy_file (self , local_file , remote_file , recurse = False ,
341
+ sftp = None ):
340
342
"""Copy local file to host via SFTP/SCP
341
-
343
+
342
344
Copy is done natively using SFTP/SCP version 2 protocol, no scp command \
343
345
is used or required.
344
-
346
+
345
347
:param local_file: Local filepath to copy to remote host
346
348
:type local_file: str
347
349
:param remote_file: Remote filepath on remote host to copy file to
348
350
:type remote_file: str
349
351
:param recurse: Whether or not to descend into directories recursively.
350
352
:type recurse: bool
351
-
353
+
352
354
:raises: :mod:`ValueError` when a directory is supplied to ``local_file`` \
353
355
and ``recurse`` is not set
354
356
:raises: :mod:`IOError` on I/O errors writing files
355
357
:raises: :mod:`OSError` on OS errors like permission denied
356
358
"""
357
359
if os .path .isdir (local_file ) and recurse :
358
- return self ._copy_dir (local_file , remote_file )
360
+ return self ._copy_dir (local_file , remote_file , sftp )
359
361
elif os .path .isdir (local_file ) and not recurse :
360
362
raise ValueError ("Recurse must be true if local_file is a "
361
363
"directory." )
362
- sftp = self ._make_sftp ()
364
+ sftp = self ._make_sftp () if not sftp else sftp
363
365
destination = self ._parent_paths_split (remote_file )
364
366
try :
365
367
sftp .stat (destination )
0 commit comments