Adding support for sftp to RCurl

While trying to download data from an FTP with the sftp protocol from R I encountered the folllowing error on my mac:

Error in function (type, msg, asError = TRUE)  : 
  Protocol "sftp" not supported or disabled in libcurl

The easiest way to fix this for me was performing the following steps:

brew install curl --with-libssh2

Then check whether sftp is now among the list of supported protocols:

/usr/local/opt/curl/bin/curl -V

Link to the new version of curl you installed:

brew link --force curl

Re-install RCurl from source:

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

And finally check if sftp is now supported:



Unknown said...

Thanks for sharing, Samuel! I ran into a problem though when following this. Homebrew curl doesn't appear to support the option --with-libssh2. I get the output "Error: invalid option: --with-libssh2". When I run "curlVersion()$protocols", I don't see sftp listed. However, when I run "curl -V", in terminal, I do see the sftp protocol listed:
curl 7.63.0 (x86_64-apple-darwin13.4.0) libcurl/7.63.0 OpenSSL/1.1.1a zlib/1.2.11 libssh2/1.8.0
Release-Date: 2018-12-12
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy
Do you know of an updated method and if so, would you consider posting or replying? I'm a beginner to all coding, and specifically R (I began coding a month or so ago when I started volunteering in a biology lab that asked me to help analyze RNA seq data), so any nudge in the right direction would be much appreciated.

Samuel Bosch said...

I no longer have access to a mac so it is difficult for me to comment on you issue. Your version of curl appears to support sftp but is clearly not the one used by RCurl. I would try again to re-install the RCurl package from source: install.packages("RCurl", type="source"). You can also explicitly set the path before installing RCurl: Sys.setenv(PATH=paste('/usr/local/opt/curl/bin', Sys.getenv('PATH'), sep=":")). See also this post with similar instructions