且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Python pysftp使用密钥文件连接到SFTP

更新时间:2022-10-31 16:23:31

要使用密钥文件进行连接,您将需要在创建连接时将路径传递给密钥文件.为此,请将参数"private_key"设置为文件的路径.

To connect using a key file, you will want to pass the path to the key file when creating the connection. To do this, you'll set the parameter "private_key" to the path to the file.

您上面的代码应如下所示:

Your code above should look something like this:

srv = pysftp.Connection(host="you_FTP_server", username="your_username", private_key="./Path/To/File")

当pySFTP发起连接时,它将尝试使用您传入的文件.如果由于密钥文件而失败,则会引发身份验证异常.

When pySFTP initiates the connection, it will try to use the file you passed in. If it fails because of the keyfile, it will throw an authentication exception.

这是我找到答案的链接: https://pysftp .readthedocs.io/en/release_0.2.7/pysftp.html .

Here's the link to where I found the answer: https://pysftp.readthedocs.io/en/release_0.2.7/pysftp.html.