Using SCP function from Rcurl in R

我与影子孤独终老i 提交于 2021-01-28 11:35:27

问题


I have tested my SSH authentication using PuTTY with success, which I mean I can ssh to remote server using the private key provided. However, I am trying to use SCP function from Rcurl package in R, I got the error message saying:

Error in function (type, msg, asError = TRUE) : Authentication failure

Here is my code

r <- scp(host='eee.com', path = "/aaa/bbb/test.sas7bdat", 
         keypasswd = NA, user = "yyyyyy", rsa = TRUE, 
         key = "C:/Users/.ssh/authorized_keys", binary = NA)

C:/Users/.ssh/authorized_keys is my private RSA key.


回答1:


the problem is that "key" must contain both the public and the private key. This should work:

r <- scp(host='eee.com', path = "/aaa/bbb/test.sas7bdat", keypasswd = NA, user = "yyyyyy", rsa = TRUE, key = c("C:/Users/.ssh/authorized_keys.pub","C:/Users/.ssh/authorized_keys"), binary = NA)



回答2:


I have had the same problem and did not get scp to work, but found a workaround in getURLContent:

x <- getURLContent("sftp://path/file", .opts = list( 
       ssh.private.keyfile = "path/keyfile",
       username="username",
       keypasswd="password"))

And the private key should be an openSSH key (I had to convert my puttygen key) and while I had to download binary content I used getBinaryURL in the end with the same arguments.



来源:https://stackoverflow.com/questions/47313391/using-scp-function-from-rcurl-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!