- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我编写了一个 Python 脚本来使用 key 身份验证连接到 SFTP 服务器。它成功连接到服务器但显示以下警告(见下文)。这是什么意思以及如何删除它。必须对代码进行哪些更改?
我的代码:
import os
import pysftp
import socket
import paramiko
import time
import os.path
import shutil
IP = "127.0.X.X"
myUsername = "USERNAME"
port = 22
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
import os
privatekeyfile = os.path.expanduser("C:\\Users\\Rohan\\.ssh\\cool.prv")
mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
try:
with pysftp.Connection(host=IP, username=myUsername,private_key=mykey,cnopts=cnopts) as sftp:
try:
r=str(socket.gethostbyaddr(IP))
print("connection successful with "+r)
except socket.herror:
print("Unknown host")
except:
print("connection failed")
警告:
UserWarning: Failed to load HostKeys from C:\Users\Rohan\.ssh\known_hosts. You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None).
warnings.warn(wmsg, UserWarning)
最佳答案
我相信这是 pysftp 中的错误。每次使用 cnopts.hostkeys = None
时都会得到这个(尽管警告实际上建议使用它)。
无论如何,你不应该使用 cnopts.hostkeys = None
,这样做会失去安全性。
有关正确的解决方案,请参阅 Verify host key with pysftp .
根据您提到的 key 身份验证,我假设您将帐户 key 误认为是主机 key 。阅读我关于 SSH key pairs 的文章了解差异。
关于python - 使用 pysftp 连接到 SFTP 服务器时出现 "Failed to load HostKeys"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56521549/
我使用 pysftp(它是 paramiko 的包装器)。 import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None sftp=pys
我正在尝试使用 pysftp 连接到服务器传输文件。 每当我运行 con = pysftp.Connection('ftp.abc.com', username='user', password='m
我正在使用 Pysftp 来 sftp 放置大量文件,并且希望在它运行时获得一些进度输出,以便我知道它是如何做的。我可以使用详细选项(或等效选项)来获取该输出吗? 谢谢。 最佳答案 我可能在这里错误地
我尝试了以下三种更改目录的方法,但它永远不会改变。还有其他人遇到过这个问题吗? import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = Non
我正在尝试使用以下脚本连接到服务器: import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None srv = pysftp.Connec
我在使用 pysftp 复制文件时遇到问题。这最初是一个有效的 WinSCP 脚本。我可以使用winscp.com 和filezilla 中下面的脚本中提供的凭据手动复制该文件。我已验证凭据是否正确并
我正在尝试编写一个脚本,以便在修改日期小于 24 小时的情况下从 SFTP 服务器检索文件。这是我迄今为止的尝试: cnopts = sftp.CnOpts() cnopts.hostkeys = N
我的代码: import pysftp s = pysftp.Connection(host='test.rebex.net', username='demo', password='password
使用 pysftp,我看到了如何在您已经连接后为任何命令设置超时,但我没有看到如何为连接本身设置超时。我觉得我在某处丢失了一些东西。只是为了尝试一下,我尝试添加 timeout=3到 Connecti
我想将我的实际私钥值作为参数传递,而不是提供文件路径。 到目前为止,我已经使用了以下代码: def upload_file_to_remote(hostname, port, username, pa
当我尝试连接时,我收到以下消息,需要一些帮助。我正在执行的脚本如下。关于如何解决此问题的任何建议? 此外,一旦我解决了这个问题,我就希望向此脚本添加监听功能,直到结果文件可用并从不同的远程目录下载它。
我正在尝试从远程服务器下载文件。为此,我需要定义“charset=ASCII”(我在 FileZilla 客户端中尝试过)。然后只有连接成功,我才能查看文件。否则我会从客户端收到“身份验证错误”(使用
我正在尝试建立到 sftp 服务器的测试连接。 (如 Python Pysftp Error 中所示)。我通过终端建立与服务器的第一个连接,从服务器获取了 key 。那工作完美无缺。但是,如果我运行
I am creating a backup script using pysftp module. I am able to upload and download files. When i am
我试图捕获 paramiko异常(exception),但它们仍被写入标准错误。 有没有办法停止在那里写? 编辑:它甚至发生在 paramiko 参与之前: import pysftp try:
我有一个用 Python 3 编写的小型服务,它使用 pysftp: with pysftp.Connection( host=host, username=connection_da
我正在使用 pysftp 库的 get_r 函数 ( https://pysftp.readthedocs.io/en/release_0.2.9/pysftp.html#pysftp.Connect
我是 Python 新手,正在编写一个使用 pysftp 模块的脚本。 pysftp 模块中有一个函数我遇到了问题——它是重命名函数。 这是电话 srv = pysftp.Connection(hos
我正在使用 python 3.3.2 和 pysftp 制作一个备份实用程序,该实用程序将文件副本存储在我网络上的另一台计算机上。 我已经知道如何使用 pysftp 来传输这些文件,但是我希望看到传输
我需要从服务器获取文件,然后将它们写入数据库。我使用: with pysftp.Connection(host, username=username, password=password, cnopt
我是一名优秀的程序员,十分优秀!