在 linux 和 windows 之间传输 pysftp.get_r 的文件
transferring files with pysftp.get_r between linux and windows
我想递归地将文件从 Linux 服务器下载到 Windows 桌面。
我正在使用以下代码:
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()
我遇到了以下错误(递归复制文件时):
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'
我知道 pysftp 正在尝试将文件夹结构从源文件夹重新创建到目标文件夹,但它在 Windows 机器上工作并且斜杠应该是反斜杠。
如何解决?
目前pysftp不支持该功能。
我会推荐 Python 的 default FTP library, which is already in the standard library (batteries included). There you can call retrbinary() 提供所需的文件夹。
我想递归地将文件从 Linux 服务器下载到 Windows 桌面。 我正在使用以下代码:
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()
我遇到了以下错误(递归复制文件时):
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'
我知道 pysftp 正在尝试将文件夹结构从源文件夹重新创建到目标文件夹,但它在 Windows 机器上工作并且斜杠应该是反斜杠。
如何解决?
目前pysftp不支持该功能。
我会推荐 Python 的 default FTP library, which is already in the standard library (batteries included). There you can call retrbinary() 提供所需的文件夹。