megatools-dl(1)
===============

NAME
----
megatools dl - download exported files and folders from Mega.nz


SYNOPSIS
--------
[verse]
'megatools dl' [--no-progress] [--print-names] [--choose-files] [--path <path>] <links>...
'megatools dl' --path - <filelink>
'megatools dl' --list <links>...


DESCRIPTION
-----------

Downloads files and folders from public links. No account is needed. Handles
links like:

* `https://mega.nz/file/7YVWhCzZ#bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_w`
* `https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg` (optionally followed by
  `/folder/<handle>` or `/file/<handle>` for a part of the folder)
* `https://mega.nz/#!7YVWhCzZ!bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_w`
  (the old form of file links)
* `https://mega.nz/#F!HIlFDajT!HLiVvQQkSe1d0ogxZuaOJg` (the old form of folder
  links)
* `https://mega.nz/?_escaped_fragment_=7YVWhCzZ!bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_w`
  (the same links in the form used by web crawlers)

The host can also be mega.co.nz, mega.app or www. followed by one of them.
A query before the `#` (tracking parameters added by web sites) and spaces
around the link are ignored. Quote the links in the shell, `#` and `!` are
special there.

A file link is downloaded into the directory `<path>`, or saved as the file
`<path>` when that doesn't exist yet. For a folder link, the contents of the
folder (with all its subfolders, including empty ones) are placed into the
directory `<path>`, which must exist, and each file and folder that is
created is printed as `F <path>` or `D <path>` (unless `--no-progress` is
given). Files that already exist are not overwritten: they are reported as
errors and the rest is downloaded.

Mega allows several files or folders with the same name in one folder. When
downloading, the oldest one keeps the name and the others are saved as
`name (1).ext`, `name (2).ext`, ... (names that are already taken by other
files in that folder are skipped).

Interrupted downloads are resumed when run again (see `--disable-resume`).

When a login is given (`-u` and `-p`, or `Username` and `Password` in the
config file), the download counts against the account's transfer quota
instead of the quota for anonymous downloads, which is useful with a paid
account. The account's files don't need to be loaded, so this login is
fast. dl doesn't ask for a password: with `-u` alone, it downloads
anonymously. Use `--ignore-config-file` to download anonymously when the
config file has a login.

To create links, use man:megatools-export[1] or the mega.nz webclient.


OPTIONS
-------

--path <path>::
	Local directory to download to (default: the current directory), or
	for a file link a new file name. A path ending with `/` must be an
	existing directory.
+
If `<path>` is `-`, the file is streamed to stdout. Only a single file
link can be streamed.

--no-progress::
	Disable download progress reporting. This is implied when streaming.

--print-names::
	Print each downloaded file, one per line: its name for a file link,
	its local path for a folder link. With `--no-progress`, nothing else
	is printed on stdout.

--choose-files::
	For folder links, print a numbered tree of the files and folders and
	ask which to download. Answer with numbers separated by spaces, ranges
	like `3-7`, or `all`. A chosen folder is downloaded with everything in
	it.

--list::
	Don't download anything, print one line per file and folder of the link
	instead: a link to just that file or folder, a space and its path
	(folder paths end with `/`). Each of the printed links can be passed to
	`megatools dl` to download only that part of the folder.

include::download-options.txt[]
include::auth-options.txt[]
include::basic-options.txt[]

<links>::
	File and folder links to download from.

<filelink>::
	Link to a file to stream.


EXIT STATUS
-----------

0 when everything was downloaded, 1 when a link is invalid or something
failed (a file that already exists, a network error, ...).


EXAMPLES
--------

* Download a file into the current directory:
+
------------
$ megatools dl 'https://mega.nz/file/7YVWhCzZ#bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_w'
------------


* Download a folder into a new directory:
+
------------
$ mkdir Photos
$ megatools dl --path Photos 'https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg'
D /home/user/Photos/2025
F /home/user/Photos/2025/beach.jpg
...
------------


* List an exported folder and download one file from it:
+
------------
$ megatools dl --list 'https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg'
https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg Photos/
https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg/folder/1Yd0FKbJ Photos/2025/
https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg/file/RlUhCALZ Photos/2025/beach.jpg
$ megatools dl 'https://mega.nz/folder/HIlFDajT#HLiVvQQkSe1d0ogxZuaOJg/file/RlUhCALZ'
------------


* Play a video without saving it:
+
------------
$ megatools dl --path - 'https://mega.nz/file/7YVWhCzZ#bauBlAkK...' | mpv -
------------


* Download with your account's transfer quota (the login comes from
  `~/.megarc`, see man:megarc[5]):
+
------------
$ megatools dl 'https://mega.nz/file/7YVWhCzZ#bauBlAkK...'
------------


include::footer.txt[]
