ftp_getBinPars: ftp_getBinPars

View source: R/ftp_getBinPars.R

ftp_getBinParsR Documentation

ftp_getBinPars

Description

Get parameters needed to download one or more remote binary file(s) to a local directory

Usage

ftp_getBinPars(host = NULL, user = NULL, pwd = NULL, hdir = NULL, ldir = NULL)

Arguments

host

Remote host URL

user

User name

pwd

Password

hdir

Host directory in which to find file(s) to download

ldir

Local directory in which to download remote files

Details

This function performs three main tasks. First, it verifies if the server can even be queried with the supplied parameters. Second, it checks whether the required information is available; this means that ftp_listDir must be able to create a table of files, with successfully parsed-out fields for type_code and name. Additionally, at least one type_code must have a value of 1, indicating a file, and not a directory. Finally, if the required criteria are all satisfied, it outputs a data.table containing the two required sets of values needed to download the files, remote_url and local_dest.

Value

If no errors, a data.table with a minimum of two fields:

  • remote_url: The full server path, with embedded credentials required to download

  • local_dest: The local destination path corresponding to each remote_url asset

In most cases, additional metadata for each remote asset will also be populated, including:

  • url_sizeMB The numeric size in megabytes

  • url_mod_year The character last modification year

  • url_mod_date The character last modification date, usually month and day

  • url_mod_time The character last modification time, usually in 24h-format

Additionally (if no errors), each output table will have two attributes:

  • local_basedir The base directory to download to

  • local_basedir_exists Does the local base directory exist?

... these are a convenient way to determine if the local target directory exists, and if not, then the attribute local_basedir can be used to create it via e.g. dir.create.

If a server error, then the error message printed to console, and:

  • call_params A list of the parameters used to query the server

If no server error, but all required return data is not detected, then an error message, and:

  • call_params A list of the parameters used to query the server

  • call_ret A nested list of the return from a call to the server using the aforementioned params via ftp_listDir

See Also

curlProgress for the function that a successful output is expected to be used for.

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

Examples

## Not run: 
## ftp parameter list
ftp_params <- list(
  host = ftp.xyz.com,
  user = "me",
  pwd = "pwd",
  dir = "/dir1/" # leading and trailing slashes will be normalized in-function
)

ftp_getBinPars(
  host = ftp_params$host,
  user = ftp_params$user,
  pwd = ftp_params$pwd,
  hdir = ftp_params$dir,
  ldir = "./local_dir_1/"
)

## End(Not run)

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