Search code examples
rcurllibcurlrcurl

sftp protocol with RCurl - last step, how to change R path to libcurl from usr/lib to usr/local/lib


First off - I know this isn't a specific code problem, so feel free to vote to close the question, but I've spent the better part of half of my day today struggling with this problem and could use some help. I also think this thread can help anybody trying to get sftp protocol working in R, since I'll share what I've done today.

I have been attempting to update RCurl so it supports sftp protocol. In R, my protocols look as such (with version and host as well):

> library(RCurl)
> curlVersion()$protocols
 [1] "dict"   "file"   "ftp"    "ftps"   "gopher" "http"   "https"  "imap"   "imaps"  "ldap"   "ldaps"  "pop3"   "pop3s"  "rtsp"   "smb"    "smbs"  
[17] "smtp"   "smtps"  "telnet" "tftp" 

> curlVersion()$version
[1] "7.43.0"

> curlVersion()$host
[1] "x86_64-apple-darwin15.0"

Not great - no sftp option...

I followed this thread - http://andrewberls.com/blog/post/adding-sftp-support-to-curl - to update curl on my machine, and was partially successful in doing so. The success part is reflected in when I run the following in the command line:

curl -V 
curl 7.55.1 (x86_64-apple-darwin15.6.0) libcurl/7.55.1 zlib/1.2.5 
libssh2/1.8.0
Release-Date: 2017-08-14
Protocols: dict file ftp gopher http imap ldap ldaps pop3 rtsp scp sftp smtp telnet tftp 
Features: AsynchDNS IPv6 Largefile libz UnixSockets 

This is great, because I've got curl updated. However, when I load RCurl and run curlVersion() in R, it's not updated. I've examined the lib folders of my /usr/ directory and have the following problem. In both my /usr/lib AND /usr/local/lib, there exists libcurl files. Specifically:

  • libcurl.3.dylib, libcurl.4.dylib, and libcurl.dylib in /usr/lib
  • libcurl.4.dylib, libcurl.dylib, libcurl.a and libcurl.la in /usr/local/lib

The files in my /usr/local/lib directory are the new files that I'd like used, however here is where my major headache began. I copied the four files from /usr/local/lib into /usr/lib and I BROKE MY COMPUTER. Many of my applications stopped loading, and I had to reinstall my OS X on account of being afraid of messing anything else up. When I reinstalled my OS X, it put my files back into their respective folders (how they look in the bullets above).

If I had to guess, I probably shouldn't have moved the .a or .la files... I'm not sure.

One last thing - when i run $ $PATH in console, I get:

$PATH
-bash: /Users/Home/.rvm/gems/ruby-2.3.3/bin:/Users/Home/.rvm/gems/ruby-2.3.3@global/bin:/Users/Home/.rvm/rubies/ruby-2.3.3/bin:/Users/Home/anaconda2/bin:/usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Users/Home/.rvm/bin: No such file or directory

/usr/local/bin is before /usr/bin. but I don't see anything with /usr/local/lib or /usr/lib - could I add these (/usr/local/lib) to my path to fix this? .libPaths() in R gives me this:

.libPaths()
"/Library/Frameworks/R.framework/Versions/3.4/Resources/library"

...if it helps at all

EDIT - I should note that the root of all problems, ofcourse, is that since 'sftp' is not listed in curlVersion()$protocols in R, that when i run RCurl::getURL(), or RCurl::ftpUpload() (im hoping to use ftpUpload), for both I receive the error:

> RCurl::ftpUpload(what = 'myfile.txt', to = 'sftp://userid:userpw@ip/'myfile.txt')
Error in function (type, msg, asError = TRUE)  : 
  Protocol "sftp" not supported or disabled in libcurl

Thanks!


Solution

  • Installing RCurl from source did the trick for me !

    install.packages("RCurl", type="source")
    

    I found the solution here - http://www.omegahat.net/RCurl/FAQ.html - specifically, the following lines.

    "I can't use scp or sftp within RCurl but the documentation for curl seems to suggest that it can. So why does RCurl not support it?

    RCurl does support it, but the likely problem is that the version of libcurl you have installed does not support it. You can check what protocols your libcurl and hence RCurl supports via the command curlVersion. If scp and sftp are not there, reinstall libcurl but with support using libssh2. You will need to have the libssh2 development libraries and headers installed before installing libcurl. On some OSes, you will need to rebuild RCurl from source."

    In general, this is a great summary of my issue from start to finish. If your version of RCurl doesn't support sftp, you need to install (at the command line) libssh2 first, then reinstall libcurl, then rebuild from source for some reason.