0

I have been using R function getURL() to load data on RStudio from a remote FTP server. However, this requires having my username and password visible in the script.

require("RCurl")
getURL("ftp://directory/filename.txt", userpwd="user:pwd")

Is there a way to hide this information?

2 Answers2

2

You could use the Keyring package.

library(keyring)
key_set(service = "curl_page", 
                 username = "joe")

Then enter your password when requested. Then you can retrieve it using:

require("RCurl")
getURL("ftp://directory/filename.txt", userpwd=key_get("curl_page",username = "joe"))
Lisa Clark
  • 340
  • 1
  • 2
  • 11
0

This is something of a guess, as I'm not familiar with R, but the normal way to do this (in any language) is to pass the username and password via environment variables that are set from an external source, such as a .env file that is not checked into your source repo, or are passed in from settings handled by your VM's hypervisor (if you have one). That way your credentials never hit your repo and do not appear directly in the source. It's also convenient if you want to run the code in different contexts, such as local, test, stage, production, etc.

This answer looks like a reasonable description of how to do this in R.

Synchro
  • 35,538
  • 15
  • 81
  • 104