fetch_url#
- pypillometry.fetch_url(url, cache_file=None, cache_dir=None, force_download=False, session=None, cache_layout='flat')[source]#
Download an HTTP(S) or SSH URL to a local file, with caching.
HTTP(S) URLs are downloaded with
download()(OSF client URLs such ashttps://osf.io/<id>are converted to download URLs).SSH URLs have the form
ssh://[user@]host[:port]/pathand are downloaded with the system’sscp, which uses~/.ssh/config(host aliases, users, keys). Only key-based login is supported: password prompts are disabled (BatchMode=yes). The path is absolute on the server; usessh://host/~/pathfor a path relative to the home directory. An SSH URL ending in/downloads the whole folder.- Parameters:
url (
str) – HTTP(S) or SSH URLcache_file (
Optional[str]) – local filename to store the download incache_dir (
Optional[str]) – directory to store the download in (used if cache_file is None); see cache_layout. If both are None, a new temporary directory is used. The location is logged.force_download (
bool) – if False (default), an existing local copy is reused; if True, the file is downloaded againsession (
Optional[Session]) – requests session for HTTP(S) downloads (e.g., fromosf_authenticate()for private OSF projects)cache_layout (
str) – where in cache_dir the download is stored:"flat"(default) uses the file name only (cache_dir/<file>),"mirror"the full remote path (cache_dir/<host>/<path>). With"flat", files with the same name from different URLs share one local copy, so the first one would be reused; use"mirror"(or force_download) in that case.
- Return type:
- Returns:
local path of the downloaded file (or folder)