moodle-cli has two ways to pull a file to disk. moodle get resolves a resource id, a Moodle URL, or a UNIT TASK phrase the same way the bare-target syntax does, then downloads it — see Daily use and moodle get for that phrase-resolution path. This page covers download (alias dl), which takes a course-module ID or an authenticated Moodle file URL directly, with no phrase resolution.

Downloading a file

dl is a real alias for download, not a separate command — both run the same code. The source is either a resource activity’s course-module ID, or an authenticated Moodle file URL on your configured site: a /mod/resource/view.php?id= URL or a /pluginfile.php/... URL. A URL on any other host is rejected.
By numeric ID, moodle-cli looks up the activity first and refuses anything that isn’t a resource activity — a folder, page, or assignment ID will not download this way (see Folder activities below).

--dest and --force

--dest <path> sets the exact downloaded file path, including its filename. Without it, moodle-cli picks a filename Moodle reports for the download, the resource’s own file entry, or the URL, in that order, and writes it into the current directory. --force replaces an existing destination file cleanly; without it, moodle-cli refuses to overwrite a file that’s already there.
get uses --to <directory> (a destination directory, keeping Moodle’s own filename) and --force, not --dest. The two commands don’t share flag names for this. See moodle get.

-o/--output is not --dest

-o, --output <file> is a global flag on every moodle-cli command: it writes the command’s rendered response (the JSON, YAML or table output) to a file instead of stdout. --dest controls where the downloaded file itself lands. They answer different questions and can both be passed at once — one redirects the summary of what happened, the other redirects the file it describes.

Folder activities and their files

A folder activity holds more than one file, so neither get nor download resolves a folder by its course-module ID directly — there’s no single file to pick. Instead, inspect the folder first:
The response lists the folder’s files, each with its own authenticated pluginfile.php URL. Pass one of those URLs to download/dl (or get) to fetch that file:
There’s no bulk “download the whole folder” — each file is a separate download.

What the command reports

Every successful download prints a summary confirming what was written: where the file landed, its name, and how many bytes came through. Scripting this? See Moodle CLI for scripts and agents for the exact JSON shape.

Failure modes

  • A URL your site doesn’t recognize as a resource or pluginfile path fails with a usage error before any request is made. A numeric ID that isn’t a resource activity fails the same way, right after moodle-cli looks up the activity to check its type.
  • A resource that resolves to more than one file refuses to guess which one you want.
  • Moodle returning a login page instead of a file means the session expired — run moodle auth login.
  • An existing destination file without --force fails rather than silently overwriting it.
See Errors and exit codes for exit codes and the JSON error shape.