Search code examples
rsshprivate-keyrcurlpassphrase

Passphrase for private key using ftpUpload function in R


I'm writing something in R which needs to upload a file to a server using SSH key authentication. I'm using the below code from the RCurl package, but the private key I'm using has a passphrase. For the life of me, I can't figure out how to specify the passphrase for the key. Has anyone got experience of using the ftpUpload function, or possibly has a better way of doing this in R?

ftpUpload(what = pathtofile,
       to = serverlocation,
       verbose = TRUE,
       .opts = list(
         ssh.private.keyfile = pathtokey
       ))

Solution

  • From the R Documentation for curlOptions and running listCurlOptions() it looks like keypasswd is what you're looking for.

    EDIT / UPDATE: I've tried adding this option to my own code and running it and it works fine for me. Your final call should look something like below:

    ftpUpload(what = pathtofile,
       to = serverlocation,
       verbose = TRUE,
       .opts = list(
         ssh.private.keyfile = pathtokey,
         keypasswd = passphrase
       ))
    

    And your output should look something like:

    *   Trying 123.456.789…
    * TCP_NODELAY set
    * Connected to 123.456.789 (123.456.789) port 22 (#0)
    * SSH MD5 fingerprint: abcdefghij123456789
    * SSH authentication methods available: publickey
    * Using SSH public key file '/Users/User1/.ssh/id_rsa.pub'
    * Using SSH private key file '/Users/User1/.ssh/id_rsa'
    * Initialized SSH public key authentication
    * Authentication complete
    * Connection #0 to host 123.456.789 left intact
    OK 
    0