1

I'm using the ftpUpload function in the RCurl package to upload files to an sftp file server. I'm having difficulty working out the authentication call.

Below is my call:

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

As a result I get:

* 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

I wasn't the one to setup the sftp server, and I'm somewhat of an ssh noob -- apologies. What I do know is that I'm able to login using my_userid and my_password with Filezilla and that the server has an .htaccess and .htpasswd file.

I'm hoping that there is some way to authenticate using ftpUpload with just my userid and password. It seems that password is one of the two available methods, but I can't seem to get ftpUpload to understand that I'd like to use the later alone.

The .htpasswd file seems to contain my_userid:my_password, though the password portion is encrypted. I'm open to loading that in a certain place for ftpUpload to access, but I'm not sure how to point ftpUpload in the right directions.

Finally, I've tried playing around with and looking through the libcurl options listed here: http://www.omegahat.org/RCurl/philosophy.html and more fully explained here: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

Alas, no luck. Any help appreciated!

Statwonk
  • 713
  • 1
  • 8
  • 21

1 Answers1

3

It seems a little late, but I am currently trying something similar (public key authentication, though) and got it working! Here is what I did:

I did set up a public key authentication basically following the instructions at http://www.howtoforge.com/set-up-ssh-with-public-key-authentication-debian-etch

That is, I run on the server the command

ssh-keygen -t rsa -C "e@mail.com" -f "ir_rsa"

to generate a public and a private key. (Just as a sidenote, I first tried to use puttygen on my local windows machine to create working keys but failed.)

Then I add the public key to the authorized keys (still on the remote server)

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

and copy both the public and private key file on the local machine where R is running. Then I can upload a file from R using

require(RCurl)
ftpUpload(what = "myfile.txt",
    to = "sftp://myusername@my.host.com:22/path/to/myfile",
    verbose = TRUE,
    .opts = list(
        ssh.public.keyfile = "path/to/local/pubkeyfile", 
        ssh.private.keyfile = "path/to/local/privatekeyfile"
    ) 
)
Karsten W.
  • 17,826
  • 11
  • 69
  • 103