Connect to SFTP with key file using Python pysftp

后端 未结 2 845
一整个雨季
一整个雨季 2020-12-18 01:29

I need to connect to a SFTP, download the most recent file, then change the file name and load again to the same SFTP folder and delete the \'original name\' file. I have do

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 01:55

    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")
    

    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.

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

提交回复
热议问题