2

I have an R script that pulls data down from QuickBase in a .csv format using RCurl. Currently, when using the write.table function I just direct it to a local folder. I am wanting to write directly to an FTP Site that I believe is using SSL. I have a username and password and can connect using clients such as cyberduck after choosing the type of connection "FTP - SSL (Explict AUTH Over TLS)".

I have tried just using the ftpUpload function but it refuses to let me to make the connection.

Any help or advice on where to look next is appreciated.

tanyrseay
  • 31
  • 2
  • Your test with cyberduck is from the same machine as the one with RCurl ? – Eugène Adell Feb 21 '18 at 21:45
  • are you able to curl using `--ftp-ssl` option from the command line? some same command can be found here https://curl.haxx.se/docs/manual.html when you search for ftp – chinsoon12 Feb 22 '18 at 02:11

1 Answers1

0

High Level

The best way I am aware of to get this done (in R) is to wrap a call to a system function. I personally use lftp, which has good handling for:

  • FTPS
  • Multiple files in/out
  • Regex and wildcard file naming

This does have the downside of being hardware specific; it's not all nicely contained in R. That said, it can potentially save you a lot of time by leveraging tools which are good at what they do.


Sample Wrapper

A wrapper for LFTP could look like the function below -- this is a variant of what I use in production; I stripped out the logging functions which depend on a broader package. At the core, this is what moves files for me.

#' lftp wrapper to get/put file(s) from ftp-like sites
#'
#' @param process list, pipeable etl objects
#' @param configuration vector (text), list of
#' arguments to supply after call to lftp
#' @param skip boolean, whether to skip this step (testing)
#'
#' @details wrapper around lftp command line tool
#'
#' @export
#'
ftp <- function(configuration, skip = FALSE) {
    if (!skip) {
        system2("lftp",
            args = configuration)
    }
}

Configuration

The biggest part of the wrapper is the configuration vector. The configuration vector lets you pass an arbitrary set of parameters to lftp, including the ones you'll need to get the job done.

A sample configuration vector could look like:

c(
    'your.ftp-server.com',
    paste("-e", '"put '/path/to/file.csv' -o '/destination/'; exit;"'
)

Noting that you need to be careful about quoting (or you can incorporate shQuote(), but that's a different project).

Putting It Together

To answer your specific question, you could use this in R to:

  • Get the data you're using from Quick Base using rCurl
  • Write it to a file somewhere on your hardware
  • Use ftp() to leverage lftp to send the file to its destination
Adam Bethke
  • 1,028
  • 2
  • 19
  • 35