作者:妃你莫属L_957 | 来源:互联网 | 2023-07-13 13:39
Iamhavinganissuecopyingfileswithpysftp.ThiswasoriginallyaWinSCPscriptthatworked.Ic
I am having an issue copying files with pysftp. This was originally a WinSCP script that worked. I can copy the file manually using the credentials supplied in the script below in winscp.com and filezilla. Ive verified that the credentials are correct and both the remote and local paths exist. the file looks like it copies ( I can see file in local directory), but it is empty. Below is the error. The same script works when connecting and downloading files from other hosts.
我在使用pysftp复制文件时遇到问题。这最初是一个有效的WinSCP脚本。我可以使用winscp.com和filezilla中下面脚本中提供的凭据手动复制文件。我已经验证了凭据是正确的,并且存在远程和本地路径。该文件看起来像是复制(我可以看到本地目录中的文件),但它是空的。以下是错误。从其他主机连接和下载文件时,相同的脚本可以正常工作。
Traceback (most recent call last):
File "C:\Users\myuser\pythonprograms\Download.py", line 28, in
main()
File "C:\Users\myuser\pythonprograms\Download.py", line 25, in main
sftp_download()
File "C:\Users\myuser\pythonprograms\Download.py", line 21, in sftp_download
sftp.get(rpath + item, lpath + item, preserve_mtime=True)
File "C:\Python27\lib\site-packages\pysftp.py", line 233, in get
self._sftp.get(remotepath, localpath, callback=callback)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 720, in get
size = self.getfo(remotepath, fl, callback)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 689, in getfo
file_size = self.stat(remotepath).st_size
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 413, in stat
t, msg = self._request(CMD_STAT, path)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 729, in _request
return self._read_response(num)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 776, in _read_response
self._convert_status(msg)
File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 804, in _convert_status
raise IOError(errno.EACCES, text)
IOError: [Errno 13] Permission denied
[Finished in 2.3s with exit code 1]
this is my code:
这是我的代码:
import pysftp
from datetime import date
from datetime import timedelta
lpath = 'C:/local/path/in/'
rpath = '/remote/path/out/'
yymd = (date.today() - timedelta(days=1)).strftime('%Y%m%d')
with pysftp.Connection('host', username='u', password='p') as sftp:
with sftp.cd():
sftp.chdir(rpath)
for item in sftp.listdir():
if yymd + '.txt' in item:
sftp.get(rpath + item, lpath + item, preserve_mtime=True)
1 个解决方案