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)
orNULL
. 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).
Examples
remoteDir <- "ftp://ftp.ncbi.nlm.nih.gov/genomes/"
if (goalie::isAnExistingUrl(remoteDir)) {
localDir <- AcidBase::tempdir2()
readme <- transmit(
remoteDir = remoteDir,
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/RtmpX02vhQ/kyf5JsjrtM-170267962600114/ncbi-readme.txt.