% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/datasus_catalog.R
\name{datasus_download}
\alias{datasus_download}
\title{Download DATASUS files}
\usage{
datasus_download(
  files = NULL,
  ...,
  dest_dir = NULL,
  overwrite = FALSE,
  timeout = 240,
  use_cache = TRUE,
  cache_dir = NULL,
  refresh = FALSE,
  verbose = TRUE
)
}
\arguments{
\item{files}{A tibble returned by \code{\link[=datasus_list_files]{datasus_list_files()}}. When \code{NULL},
additional filters are forwarded to \code{\link[=datasus_list_files]{datasus_list_files()}}.}

\item{...}{Filters passed to \code{\link[=datasus_list_files]{datasus_list_files()}} when \code{files} is \code{NULL}.}

\item{dest_dir}{Optional destination directory. When \code{NULL} and
\code{use_cache = TRUE}, the package cache directory is used.}

\item{overwrite}{Logical. Overwrite existing files (default \code{FALSE}).}

\item{timeout}{Timeout in seconds for each download (default 240).}

\item{use_cache}{Logical. Store and reuse downloads in the cache directory
(default \code{TRUE}).}

\item{cache_dir}{Optional cache directory.}

\item{refresh}{Logical. Force re-download even when a cached file exists
(default \code{FALSE}).}

\item{verbose}{Logical. Emit progress messages (default \code{TRUE}).}
}
\value{
A tibble with a \code{local_file} column containing the paths to the
downloaded files, plus a \code{downloaded} flag.
}
\description{
Downloads one or many DATASUS files. When \code{use_cache = TRUE}, files that
already exist in the cache directory are reused instead of re-downloaded.
}
\examples{
\donttest{
tryCatch({
  files <- datasus_list_files(
    source = "SIHSUS", file_type = "RD",
    year = 2024, month = 1, uf = "AC",
    verbose = FALSE
  )
  downloads <- datasus_download(
    files,
    cache_dir = tempdir(),
    verbose   = FALSE
  )
}, error = function(e) message("FTP unavailable: ", conditionMessage(e)))
}
}
