MEGAcmd Documentation

repository·master·Indexed 24 days ago

https://github.com/meganz/megacmd

A command-line interface and scriptable application providing non-UI access to MEGA services. It supports synchronization, remote backups with historical snapshots, WebDAV/streaming capabilities, and non-interactive shell commands (mega-*) for automation. The tool includes an interactive shell (MEGAcmdShell) and a background server (MEGAcmdServer) to manage sessions, configuration, and file transfers across Windows, macOS, and Linux.

Tokens
36.6K
Snippets
126
Records
226
Agent score
80%

What's inside MEGAcmd

  1. Core MEGAcmd features

    master

    MEGAcmd provides the following capabilities:

    • File Management: Move files between your local PC and your MEGA account via CLI.
    • Automation: Use commands in scripts for file management.
    • Synchronization & Backup: Set up scheduled syncs or backups between local folders and MEGA using sync or backup commands.
    • WebDAV: Access your MEGA files via WebDAV using the webdav command.
    • FUSE Mount (Linux only): Mount your MEGA cloud folder to your local filesystem using the fuse-add command.
  2. Overview of MEGAcmd interaction modes

    master

    MEGAcmd provides non-UI access to MEGA services through two primary modes of interaction. Both modes require the MEGAcmdServer to be running (it starts automatically when you launch a shell or execute a command).

    1. Interactive Mode: Uses MEGAcmdShell to provide an interactive shell where you can type commands, arguments, and flags. You can use help to list commands and command --help for specific details.
    2. Non-interactive Mode (Scriptable): Uses individual mega-* client commands (e.g., mega-put, mega-cd) that can be executed from a shell, script, or another program. These commands return a non-zero exit code on failure.

    Session Persistence: When you log in, your session, synced folders, cache databases, and configuration are stored in your local home folder. Restarting the server restores your previous session. To permanently end a session and clean data, you must use the logout command.

  3. Manage MEGAcmd Sessions

    master

    A session is created when you log in with your email and password. Sessions persist until you log out or kill them.

    • View active sessions: Use whoami -l to see all open sessions across all devices.
    • Terminate a session: Use killsession to close a session.

    Warning: Killing a session immediately closes the connection for the device using it. Since sync, backup, and WebDAV configurations are tied to a session, logging out will cancel these active processes.

  4. Use Regular Expressions in MEGAcmd

    master

    MEGAcmd supports pattern matching via several methods depending on how it was compiled:

    1. PCRE (Perl Compatible Regular Expressions): If compiled with PCRE (enabled by default), use the --use-pcre flag with commands like find.
    2. C++11: If PCRE is not available, C++11 regular expressions are used.
    3. Wildcards: If neither of the above is available, you can only use standard wildcards:
      • *: Matches any number of characters.
      • ?: Matches a single unknown character.

    Important for Non-interactive mode: When using patterns in a standard shell, you must escape shell symbols (e.g., \*) or wrap the pattern in quotes (e.g., "*.txt") to prevent the shell from expanding them before they reach MEGAcmd.

  5. Configure WebDAV Access

    master
    The webdav command allows you to access your MEGA folders or files as if they were local files on your device. This can be used to mount a MEGA folder as a local drive or to provide a URL that a browser can use to access files on your PC.
  6. How MEGA-FUSE works

    master

    MEGA-FUSE allows you to serve your MEGA cloud files as a 'Filesystem in Userspace' (FUSE). Once configured, you can browse, play, and edit your MEGA files using your local computer's standard file management tools as if they were stored locally.

    Local Cache

    To manage files, MEGAcmd uses a local cache to store both downloaded files and files being uploaded.

    • Linux/macOS path: $HOME/.megaCmd/fuse-cache
    • Windows path: %LOCALAPPDATA%\MEGAcmd\.megaCmd\fuse-cache

    Important: The cache is fundamental for FUSE mounts to function. Files are removed automatically, but restarting the MEGAcmd Server can help reclaim space if the cache grows too large.

    Streaming and Storage

    Streaming is not directly supported. To open a file via a FUSE mount, the file must be completely downloaded to the local cache folder first. Ensure you have sufficient hard drive space to accommodate these files.

  7. Understand MEGAcmd logging categories and levels

    master

    MEGAcmd logs are divided into two distinct categories, each with its own log level. You can adjust these levels using the log command.

    Log Categories

    • cmd: Messages reported by MEGAcmd itself regarding user command processing.
    • sdk: Messages reported by the SDK and dependent libraries regarding requests, transfers, network, etc.

    Log Levels

    Levels range from FATAL (lowest) to VERBOSE (highest). Each log message is prefixed with its category (cmd or sdk) and its level (e.g., DBG, INFO, DTL).

    Example log format: 2025-02-07_16-47-56.662269 cmd DBG Registering state listener...

  8. Understand MEGAcmd execution modes: Interactive vs Scriptable

    master

    MEGAcmd can be used in two primary ways:

    1. Interactive Mode: Running the mega-cmd shell where you type commands directly into a command-line interface.
    2. Scriptable Mode: Running commands directly from your system shell (e.g., bash, zsh, cmd.exe). To do this, prefix any command with mega-. For example, if the interactive command is ls, the scriptable version is mega-ls.

    Key Terminology:

    • Remote Path: Refers to a file or folder located in your MEGA cloud account online.
    • Local Path: Refers to a file or folder on your local device where MEGAcmd is running.
    • Verbosity: You can increase the amount of information returned by any command by passing -v (e.g., -vv, -vvv).
  9. Understand sync RUN_STATE and STATUS values

    master

    When inspecting synchronizations, the output includes two key state indicators: RUN_STATE and STATUS.

    RUN_STATE (Execution Lifecycle):

    • Pending: Sync config loaded, but the sync has not yet attempted to start.
    • Loading: Sync is currently loading from disk.
    • Running: Sync is loaded and active.
    • Suspended: Sync is not loaded, but exists on disk with its last known state.
    • Disabled: Sync has been disabled; starting it will behave like a brand new configuration.

    STATUS (Transfer State):

    • NONE: Status is unknown.
    • Synced: No transfers or pending actions are ongoing.
    • Pending: The sync engine is performing calculations.
    • Syncing: Transfers or pending actions are currently being carried out.
    • Processing: State cannot be determined (the engine is too busy; try again later).
    • ERROR: Indicates an error occurred (check the ERROR column for details).
  10. Manage custom attributes with `--force-non-official`

    master

    MEGAcmd distinguishes between official attributes and custom attributes. Custom attributes are internally stored with a _ prefix.

    If you want to show, modify, or delete a custom attribute that shares the same name as an official attribute, you must use the --force-non-official flag. This allows you to bypass the official attribute name and interact with the version prefixed with _.

  11. How MEGAcmd execution modes work

    master

    MEGAcmd can be used in two primary ways:

    1. Interactive Mode: The shell processes commands directly as you type them.
    2. Scriptable Mode: Commands are run from a system shell (like bash on Linux/macOS or Command Prompt on Windows), allowing them to be used in automation scripts.

    To enable features like synchronization and backup, MEGAcmd runs a background server process. This process forwards requests from the shell or scripts.

    • To close the interactive shell but keep the background server running (to maintain sync/backup), use: quit --only-shell.
    • To close everything, use: quit.
  12. Display and manage FUSE mounts

    master

    Use the following commands to view and control your active FUSE mounts:

    List all mounts

    To see a summary of all existing mounts (including name, local path, remote path, persistence, and enabled status), use:

    $ fuse-show

    To get detailed information about a specific mount, provide its name or local path:

    $ fuse-show <NAME|LOCAL_PATH>

    Enable or disable a mount

    To make cloud files accessible locally or to stop exposing them, use fuse-enable or fuse-disable:

    $ fuse-enable <NAME|LOCAL_PATH>
    $ fuse-disable <NAME|LOCAL_PATH>

    Note: Disabled mounts still exist and will appear in fuse-show results.

    Remove a mount

    To permanently delete a mount configuration, use fuse-remove. Requirement: You must disable the mount using fuse-disable before it can be removed.

    $ fuse-remove <NAME|LOCAL_PATH>
    $ fuse-show
    $ fuse-enable <NAME|LOCAL_PATH>
    $ fuse-disable <NAME|LOCAL_PATH>
    $ fuse-remove <NAME|LOCAL_PATH>