小编poo*_*gar的帖子

将私钥作为字符串/文本传递,而不是在 Python PYSFTP 中传递文件路径

我想传递我的实际私钥值作为参数,而不是提供文件路径。

到目前为止我已经使用了以下代码:

import pysftp
import os

cnopts = pysftp.CnOpts()
if str(host_keys).lower() =='none':
    cnopts.hostkeys = None
else:
    cnopts.hostkeys.load(hostkeys)
filename = os.path.basename(localpath)
print(filename)
remotepath = os.path.join(remotefolder, filename)
print(remotepath)
with pysftp.Connection(host=hostname, port=int(port), username=username, password=password, cnopts=cnopts,private_key=private_key_filepath) as sftp:
    sftp.put(localpath, remotepath=remotepath)
Run Code Online (Sandbox Code Playgroud)

请建议某种方式将其作为文本传递。

例子:

private_key='abcdmyprivatekeytext'
Run Code Online (Sandbox Code Playgroud)

在实际场景中,我会将我的私钥文本放置在安全保管库中。

python ssh sftp pysftp private-key

6
推荐指数
1
解决办法
6917
查看次数

标签 统计

private-key ×1

pysftp ×1

python ×1

sftp ×1

ssh ×1