[英]transferring files with pysftp.get_r between linux and windows
I want to recursively download files from a Linux server into a Windows desktop. 我想将文件从Linux服务器递归下载到Windows桌面。 I'm using the following code:
我正在使用以下代码:
import pysftp
import sys
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(host="192.168.1.1", username="user", password="secret", cnopts=cnopts) as sftp:
sftp.get_r ('test_sftp', 'C:\\Users\\user\\Desktop\\my_dir\\', preserve_mtime=False)
sftp.close()
I have the encoutered the following error (while recursively copying the files): 我遇到了以下错误(递归复制文件时):
Traceback (most recent call last):
File "blah.py", line 12, in <module>
sftp.get_r ('teste_sftp', 'C:\\Users\\user\\Desktop\\my_dir\\', preserve_mtime=False)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\pysftp\__init__.py", line 311, in get_r
preserve_mtime=preserve_mtime)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\pysftp\__init__.py", line 249, in get
self._sftp.get(remotepath, localpath, callback=callback)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\paramiko\sftp_client.py", line 720, in get
with open(localpath, 'wb') as fl:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Desktop\\my_dir\\test_sftp/n1/M51'
I understand that pysftp is trying to recreate the folder structure from the source into the destination folder, but it isn't sensible to the fact that it is working on a Windows machine and that the slashes should be backslashes. 我知道pysftp尝试将文件夹结构从源重新创建到目标文件夹,但是对于在Windows机器上工作且斜杠应该是反斜杠的事实并不明智。
How to work around it? 如何解决呢?
Currently, pysftp doesn't have support for such feature. 目前,pysftp不支持该功能。
I would recommend Python's default FTP library , which is already in the standard library ( batteries included ). 我建议使用Python的默认FTP库 ,该库已经在标准库中( 包括电池 )。 There you can call retrbinary() giving the desired folder.
在那里,您可以调用retrbinary()来提供所需的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.