0

I've read a few posts on sftp with R, but was not able to address the problem that I have. There's a decent change I'm just not searching in the right place, and if that's the case, please point me in the right direction. Here's where I'm at:

> library(RCurl)
> curlVersion()
$age
[1] 3

$version
[1] "7.43.0"

$vesion_num
[1] 469760

$host
[1] "x86_64-apple-darwin15.0"

$features
     ipv6       ssl      libz      ntlm asynchdns    spnego largefile   ntlm_wb 
        1         4         8        16       128       256       512     32768 

$ssl_version
[1] "SecureTransport"

$ssl_version_num
[1] 0

$libz_version
[1] "1.2.5"

$protocols
 [1] "dict"   "file"   "ftp"    "ftps"   "gopher" "http"   "https"  "imap"   "imaps"  "ldap"   "ldaps"  "pop3"   "pop3s"  "rtsp"   "smb"    "smbs"   "smtp"   "smtps"  "telnet" "tftp"  

$ares
[1] ""

$ares_num
[1] 0

$libidn
[1] ""

Right away, I notice that sftp is not a protocol accepted in my current version of RCurl, which is my main problem. As a result, when I run the following code below, I get the following error:

# Input 
protocol <- "sftp"
server <- "00.000.00.00"
userpwd <- "userid:userpass"
tsfrFilename <- 'myfile.txt'
ouptFilename <- 'myfile.txt'

# Run
url <- paste0(protocol, "://", server, tsfrFilename)
data <- getURL(url = url, userpwd = userpwd)

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

I actually have a second question as well. My understanding is that getURL grabs data from the other server and pulls it to my local machine, whereas I would like to put a file onto the server from my local machine.

To summarize: (1) can I update RCurl / libcurl in R to support sftp, and (2) how do i put files from my local machine into the server, rather than get files from the server to my local machine?

Thanks!

Canovice
  • 9,012
  • 22
  • 93
  • 211

2 Answers2

1

I found the answer, for the most part...

http://andrewberls.com/blog/post/adding-sftp-support-to-curl - following this link addressed the problem for me.

I've successfully added sftp support to cURL, however I am now struggling to update the RCurl package to have the same...

Canovice
  • 9,012
  • 22
  • 93
  • 211
0

Windows 10, 11, Server 2019 and Server 2022 come by default with cURL already installed. This version does not and will not support SFTP.

You'll need to download another cURL

You'll need to put this downloaded version as one of the earliest entries in your PATH variable. Only then you are sure you use the cURL with SFTP support.

Upload using the structure from the following example: curl -k "sftp://83.46.38.23:22/CurlPutTest/" --user "testuser:testpassword" -T "C:\test\testfile.xml" --ftp-create-dirs

Download using the structure from the following example: curl -k "sftp://83.46.38.23:22/CurlPutTest/testfile.xml" --user "testuser:testpassword" -o "C:\test\testfile.xml" --ftp-create-dirs

starball
  • 20,030
  • 7
  • 43
  • 238