Paramiko get() 引发 IOError “No such file"如果服务器不支持 df -hi [英] Paramiko get() raises IOError "No such file" if server doesn't support df -hi

查看:67
本文介绍了Paramiko get() 引发 IOError “No such file"如果服务器不支持 df -hi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 paramiko 的问题,当我尝试从远程服务器获取文件时,它给了我 IOError: [Errno 2] No such file.这是我的代码:

I'm running into a problem with paramiko where it gives me IOError: [Errno 2] No such file when I try to get a file off the remote server. Here's my code:

# set up a transport object t (using an rsa key), which connected successfully
>>> t.is_active()
True
>>> sftp = paramiko.SFTPClient.from_transport(t)
>>> files = sftp.listdir()  # files holds the list ['canceled', 'downloaded', 'FILE.06222012.TXT']
>>> sftp.get(files[2], '.')
IOError: [Errno 2] No such file

但是,当我在命令行上连接到 sftp 时(作为我打开 python repl 的同一用户),我可以获取文件.有什么想法吗?

However, when I connect to sftp on the command line (as the same user I opened the python repl with) I can get the file. Any ideas?

我发现这篇文章似乎是我遇到的问题https://bugs.launchpad.net/paramiko/+bug/492238 在交互式 sftp 提示中:

I found this post which seems like the issue I'm having https://bugs.launchpad.net/paramiko/+bug/492238 In the interactive sftp prompt:

sftp> df -hi
Server does not support statvfs@openssh.com extension

此错误来自 2009 年,并未关闭(但我使用的是最新的 paramiko 1.7.7.1).有人知道解决方法吗?我可以强制 paramiko 只执行与普通 sftp get 等效的操作,而不尝试检查文件完整性吗?

This bug is from 2009 and wasn't closed out (but I'm using the latest paramiko 1.7.7.1). Anyone know of a workaround? Can I force paramiko to just do the equivalent of plain sftp get, without trying to check file integrity?

推荐答案

我遇到了同样的问题,但是我没有因为 sftp 和 df 遇到问题.确保为 localpath 提供正确的文件名!

I had the same issues, however, I did not run into problems because of sftp and df. Make sure to give a proper filename for localpath!

sftp.get(files[2],'file2.txt')

这篇关于Paramiko get() 引发 IOError “No such file"如果服务器不支持 df -hi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆