2012-09-05 46 views
1

我使用的RCurlftpUpload功能將文件上傳到SFTP文件服務器。我很難完成驗證呼叫。SSH密碼認證方式在RCurl

下面是我的電話:

ftpUpload(what = "some-file.png", 
     to = "sftp://some-ftp-server.com:22/path/to/some-file.png", 
     verbose = TRUE, 
     userpwd = "my_userid:my_password") 

結果我得到:

* About to connect() to some-ftp-server.com port 22 (#0) 
* Trying some-ftp-server.com... * connected 
* Connected to some-ftp-server.com (some ip address) port 22 (#0) 
* SSH authentication methods available: publickey,password 
* Using ssh public key file /home/.ssh/id_dsa.pub 
* Using ssh private key file /home/.ssh/id_dsa 
* SSH public key authentication failed: Unable to open public key file 
* Authentication failure 
* Closing connection #0 
Error in function (type, msg, asError = TRUE) : Authentication failure 

我不是一個設置SFTP服務器,我有點一個SSH小白 - 道歉。我所知道的是,我可以在使用my_useridmy_password與Filezilla的和服務器有一個.htaccess.htpasswd文件登錄。

我希望有某種方式使用ftpUpload只有我的用戶名和密碼進行身份驗證。看起來password是兩種可用的方法之一,但我似乎無法得到ftpUpload明白,我想單獨使用後者。

.htpasswd文件似乎包含my_userid:my_password,儘管密碼部分是加密的。我打算加載在某個地方的ftpUpload訪問,但我不知道如何指向ftpUpload在正確的方向。

最後,我試着打周圍,並通過這裏列出的選項的libcurl尋找:http://www.omegahat.org/RCurl/philosophy.html這裏更充分的解釋:http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

唉,沒有運氣。任何幫助感謝!

回答

1

這似乎有點晚了,但我目前正在類似的東西(公共密鑰認證,雖然),並得到它的工作! 這裏是我做過什麼:

我沒有設置基本上按照說明公鑰認證在http://www.howtoforge.com/set-up-ssh-with-public-key-authentication-debian-etch

也就是說,我在服務器上運行命令

ssh-keygen -t rsa -C "[email protected]" -f "ir_rsa" 

生成一個公共和一個私鑰。 (正如一個旁註,我第一次嘗試使用 的puttygen我的本地Windows機器上創建工作密鑰,但失敗了。)

然後我 公鑰添加到授權密鑰(仍然在遠程服務器上)

mkdir ~/.ssh 
chmod 700 ~/.ssh 
cat id_rsa.pub >> ~/.ssh/authorized_keys 
chmod 600 ~/.ssh/authorized_keys 

並在運行 R的本地機器上覆制公鑰和私鑰文件。然後,我可以使用上傳來自R文件

require(RCurl) 
ftpUpload(what = "myfile.txt", 
    to = "sftp://[email protected]:22/path/to/myfile", 
    verbose = TRUE, 
    .opts = list(
     ssh.public.keyfile = "path/to/local/pubkeyfile", 
     ssh.private.keyfile = "path/to/local/privatekeyfile" 
    ) 
)