Skip to contents

Utility function that supports easy file matching and download from a remote FTP server. Also enables on-the-fly file renaming and compression.

Usage

transmit(
  remoteDir,
  localDir = getwd(),
  pattern = NULL,
  rename = NULL,
  compress = FALSE,
  download = TRUE
)

Arguments

remoteDir

character(1). Remote FTP directory path.

localDir

character(1). Directory where to save files locally.

pattern

character(1). Pattern to use for matching.

rename

character(1) or NULL. Rename the local files (including suffix), if desired.

compress

logical(1). Compress the downloaded files.

download

logical(1). Download files (default) or only return the matching URL(s).

Value

Invisible character. Local file paths.

Note

Updated 2022-06-02.

Examples

try({
    localDir <- AcidBase::tempdir2()
    readme <- transmit(
        remoteDir = "ftp://ftp.ncbi.nlm.nih.gov/genomes/",
        localDir = localDir,
        pattern = "^README\\.txt$",
        rename = "ncbi-readme.txt",
        compress = FALSE
    )
    basename(readme)
    file.exists(readme)
    AcidBase::unlink2(localDir)
})
#> → Transmitting files from <ftp://ftp.ncbi.nlm.nih.gov/genomes/>.
#>  1 file matching pattern: README.txt.
#> → Downloading ncbi-readme.txt.
#> → Downloading <ftp://ftp.ncbi.nlm.nih.gov/genomes/README.txt> to /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmpqe7MQ5/mike-1668088725.57126-wgsqcjoudf/ncbi-readme.txt.