ftp_makeParams: Construct params to interact with an FTP endpoint

View source: R/ftp_makeParams.R

ftp_makeParamsR Documentation

Construct params to interact with an FTP endpoint

Description

Create url strings and, optionally, authentication parameters for FTP endpoint interactions

Usage

ftp_makeParams(host, protocol = "ftp", user = NULL, pwd = NULL, extras = NULL)

Arguments

host

(required) The host address string. Should take the form of ftp.your_host.com

protocol

(optional) The protocol to use; defaults to ftp

user

(optional) User login name, if host access requires authentication. If provided, pwd must also be a valid string

pwd

(optional) User password, if host access requires authentication. If provided, user must also be a valid string

extras

(optional) Additional arguments to pass to output. If provided, must be a named vector.

Details

This is a simple helper function that is most useful for constructing argument-lists to pass to e.g. getURL; the outputs are named with this use case in mind. See examples.

This function normalizes common variants of input formats for host and protocol. See examples.

Value

If extras are not supplied, a named list of length 2, containing the url and userpwd. If either user or pwd are missing OR are blank, the second element will be NULL.

If extras are supplied, a named list of length 2 plus length(extras).

See Also

Other ftp_functions: ftp_getBinPars(), ftp_listDir(), ftp_parseMeta()

Examples

# with authentication
ftp_makeParams(host = "ftp.123.com", user = "myself", pwd = "my_pwd")

# NULL or blank for either of user or pwd will result in NULL userpwd
ftp_makeParams(host = "ftp.123.com", user = "myself", pwd = " ")

# host and protocol input normalization
x0 <- ftp_makeParams(host = "ftp.123.com", protocol = "ftp" )
x1 <- ftp_makeParams(host = "ftp://ftp.123.com", protocol = "ftp")
x2 <- ftp_makeParams(host = "ftp://ftp.123.com", protocol = "ftp://")
x3 <- ftp_makeParams(host = "ftp://ftp.123.com")

all(sapply(list(x1, x2, x3), function(f) identical(x0, f)))

# If you wanted to get a listing of all files:
## Not run: 
library(RCurl)
my_params <- ftp_makeParams(host = "ftp.123.com", user = "myself", pwd = "my_pwd")
my_params$ftplistonly <- TRUE
do.call(getURL, my_params)

## End(Not run)

slin30/wzMisc documentation built on Jan. 27, 2023, 1 a.m.