我想传递我的实际私钥值作为参数,而不是提供文件路径。
到目前为止我已经使用了以下代码:
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)
在实际场景中,我会将我的私钥文本放置在安全保管库中。