Using RCurl with SFTP

Statwonk picture Statwonk · Sep 4, 2012 · Viewed 8.8k times · Source

I'm attempting to use the ftpUpload in the RCurl package for the first time.

The site I'm trying to access uses the sftp protocol. I've made sure to install the version of libcurl that includes the ability to make secure connections.

SFTP is listed among the protocols available to RCurl:

curlVersion()$protocols
[1] "dict"   "file"   "ftp"    "ftps"   "gopher"
[6] "http"   "https"  "imap"   "imaps"  "ldap"  
[11] "pop3"   "pop3s"  "rtmp"   "rtsp"   "scp"   
[16] "sftp"   "smtp"   "smtps"  "telnet" "tftp"

Yet, when I run the fileUpload function I get:

ftpUpload(what = "some_file.png",
          to = "userid:password@sftp://ec2-some-server-ip.compute-1.amazonaws.com")

Error in function (type, msg, asError = TRUE)  : 
Couldn't resolve host 'sftp'

I have also tried breaking the userid and password out in terms of parameterization, but I get the same response.

Any suggestions would be appreciated.

Answer

RichardE picture RichardE · Aug 18, 2017

The userid and password need to be after the protocol (thats why you're getting the cannot find host sftp error):

ftpUpload(what = "some_file.png",
      to = "sftp://userid:[email protected]:22/path/some_file.png")

I also suggest including the port number after the host in case it's not the default and the file path on the server where you want it to go.