137
137
_SFTPPatList = List [Union [bytes , List [bytes ]]]
138
138
_SFTPStatFunc = Callable [[_SFTPPath ], Awaitable ['SFTPAttrs' ]]
139
139
140
+ _SFTPClientFileOrPath = Union ['SFTPClientFile' , _SFTPPath ]
141
+
140
142
_SFTPNames = Tuple [Sequence ['SFTPName' ], bool ]
141
143
_SFTPOSAttrs = Union [os .stat_result , 'SFTPAttrs' ]
142
144
_SFTPOSVFSAttrs = Union [os .statvfs_result , 'SFTPVFSAttrs' ]
@@ -799,6 +801,22 @@ async def run_task(self, offset: int, size: int) -> Tuple[int, int]:
799
801
async def run (self ) -> None :
800
802
"""Perform parallel file copy"""
801
803
804
+ if self ._srcfs == self ._dstfs and \
805
+ isinstance (self ._srcfs , SFTPClient ):
806
+ try :
807
+ await self ._srcfs .remote_copy (self ._srcpath , self ._dstpath )
808
+ except SFTPOpUnsupported :
809
+ pass
810
+ else :
811
+ self ._bytes_copied = self ._total_bytes
812
+
813
+ if self ._progress_handler :
814
+ self ._progress_handler (self ._srcpath , self ._dstpath ,
815
+ self ._bytes_copied ,
816
+ self ._total_bytes )
817
+
818
+ return
819
+
802
820
try :
803
821
self ._src = await self ._srcfs .open (self ._srcpath , 'rb' ,
804
822
block_size = 0 )
@@ -808,24 +826,6 @@ async def run(self) -> None:
808
826
if self ._progress_handler and self ._total_bytes == 0 :
809
827
self ._progress_handler (self ._srcpath , self ._dstpath , 0 , 0 )
810
828
811
- if self ._srcfs == self ._dstfs and \
812
- isinstance (self ._srcfs , SFTPClient ):
813
- try :
814
- await self ._srcfs .remote_copy (
815
- cast (SFTPClientFile , self ._src ),
816
- cast (SFTPClientFile , self ._dst ))
817
- except SFTPOpUnsupported :
818
- pass
819
- else :
820
- self ._bytes_copied = self ._total_bytes
821
-
822
- if self ._progress_handler :
823
- self ._progress_handler (self ._srcpath , self ._dstpath ,
824
- self ._bytes_copied ,
825
- self ._total_bytes )
826
-
827
- return
828
-
829
829
async for _ , datalen in self .iter ():
830
830
if datalen :
831
831
self ._bytes_copied += datalen
@@ -4283,9 +4283,9 @@ async def mcopy(self, srcpaths: _SFTPPaths,
4283
4283
block_size , max_requests , progress_handler ,
4284
4284
error_handler )
4285
4285
4286
- async def remote_copy (self , src : SFTPClientFile , dst : SFTPClientFile ,
4287
- src_offset : int = 0 , src_length : int = 0 ,
4288
- dst_offset : int = 0 ) -> None :
4286
+ async def remote_copy (self , src : _SFTPClientFileOrPath ,
4287
+ dst : _SFTPClientFileOrPath , src_offset : int = 0 ,
4288
+ src_length : int = 0 , dst_offset : int = 0 ) -> None :
4289
4289
"""Copy data between remote files
4290
4290
4291
4291
:param src:
@@ -4298,8 +4298,12 @@ async def remote_copy(self, src: SFTPClientFile, dst: SFTPClientFile,
4298
4298
The number of bytes to attempt to copy
4299
4299
:param dst_offset: (optional)
4300
4300
The offset to begin writing data to
4301
- :type src: :class:`SSHClientFile`
4302
- :type dst: :class:`SSHClientFile`
4301
+ :type src:
4302
+ :class:`SSHClientFile`, :class:`PurePath <pathlib.PurePath>`,
4303
+ `str`, or `bytes`
4304
+ :type dst:
4305
+ :class:`SSHClientFile`, :class:`PurePath <pathlib.PurePath>`,
4306
+ `str`, or `bytes`
4303
4307
:type src_offset: `int`
4304
4308
:type src_length: `int`
4305
4309
:type dst_offset: `int`
@@ -4309,6 +4313,12 @@ async def remote_copy(self, src: SFTPClientFile, dst: SFTPClientFile,
4309
4313
4310
4314
"""
4311
4315
4316
+ if isinstance (src , (bytes , str , PurePath )):
4317
+ src = await self .open (src , 'rb' , block_size = 0 )
4318
+
4319
+ if isinstance (dst , (bytes , str , PurePath )):
4320
+ dst = await self .open (dst , 'wb' , block_size = 0 )
4321
+
4312
4322
await self ._handler .copy_data (src .handle , src_offset , src_length ,
4313
4323
dst .handle , dst_offset )
4314
4324
0 commit comments