• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

build/H23-Mar-2021-4,9533,830

contrib/H23-Mar-2021-1,153882

sdk/H03-May-2022-323,210223,905

src/H23-Mar-2021-32,49127,193

tests/H23-Mar-2021-3,7292,335

.gitignoreH A D23-Mar-20212.1 KiB126112

.gitmodulesH A D23-Mar-202171 43

LICENSEH A D23-Mar-20211.7 KiB3528

Makefile.amH A D03-May-20221.3 KiB6021

README.mdH A D23-Mar-202113.9 KiB304194

UserGuide.mdH A D23-Mar-202159.5 KiB1,2371,020

autogen.shH A D23-Mar-202137 31

clean.shH A D23-Mar-20211.7 KiB4425

configure.acH A D03-May-202213.6 KiB479409

README.md

1# MEGAcmd - Command Line Interactive and Scriptable Application
2
3MEGAcmd provides non UI access to MEGA services. It intends to offer all the
4functionality with your MEGA account via commands. It features **synchronization**
5, **backup** of local folders into your MEGA account and a **webdav/streaming** server.
6
7See [`Usage Examples`](#usage-examples).
8
9Available packages for MEGAcmd in all supported platforms should be found
10[here](https://mega.nz/cmd). If the package fails to install, read below for the requirements.
11
12**It supports 2 modes of interaction:**
13
14- **Interactive** - A shell to query your actions
15- **Scriptable** - A way to execute commands from a shell/a script/another program
16
17In order to provide those 2 modes, it features one server (**MEGAcmdServer**), an interactive shell (**MEGAcmdShell**) and several commands that will launch the non-interactive client (**MEGAcmdClient**).
18
19See [`Usage`](#usage) and [`Platform`](#platforms) to understand how to use it in your particular system.
20
21# Building MEGAcmd
22If you wish to build or install MEGAcmd, here are a list of requirements and instructions.
23
24## Requirements
25
26The requirements are the same as those for the sdk (usually `cryptopp, zlib, sqlite3, cares, libuv, ssl, curl, sodium, readline` for platforms *other than Windows*. It is recommended to include `pcre` to have support for regular expressions.
27
28In order to have support for thumbnails and previews, it is highly recommended to have `ffmpeg` (`libavcodec-dev libavutil-dev libavformat-dev libswscale-dev`) and `mediainfo`(`libmediainfo-dev + libzen-dev`) for media file attributes.
29
30**For convenience, here is a list of packages for common Linux Distros and precompiled third party dependencies for other Operative Systems:**
31 * **Ubuntu 16.04**
32	 * `autoconf libtool g++ libcrypto++-dev libz-dev libsqlite3-dev libssl-dev libcurl4-openssl-dev libreadline-dev libpcre++-dev libsodium-dev libc-ares-dev libfreeimage-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libmediainfo-dev libzen-dev`
33
34 * **Ubuntu 18.04**
35	 * `autoconf libtool g++ libcrypto++-dev libz-dev libsqlite3-dev libssl-dev libcurl4-gnutls-dev libreadline-dev libpcre++-dev libsodium-dev libc-ares-dev libfreeimage-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libmediainfo-dev libzen-dev libuv1-dev`
36
37 * **Debian 9**
38
39	* `libcrypto++ libpcrecpp0v5 libc-ares-dev zlib1g-dev libuv1 libssl-dev libsodium-dev readline-common sqlite3 curl autoconf libtool g++ libcrypto++-dev libz-dev libsqlite3-dev libssl-dev libcurl4-gnutls-dev libreadline-dev libpcre++-dev libsodium-dev libc-ares-dev libfreeimage-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libmediainfo-dev libzen-dev`
40	* In some instanances you may need to run
41		 `apt install --reinstall build-essential`
42
43* **Windows**
44
45	* For Windows, here is a bundle with all the 3rd party dependencies required to build:
46	https://mega.nz/#!MkZmVazb!fffUvFV9pIQhr__dVipwWqFfvjDEEp0JUsT8WBKAbRg
47
48* **MacOS**
49
50	* For MacOS, here is a bundle with all the 3rd party dependencies required to build, plus a `config.h` file to be placed at `sdk/include/mega/config.h`:
51	https://mega.nz/#F!WwZyBZRL!1vXiBr7pJZLINpSRErBxvA
52
53## Getting the source
54
55Ensure you obtain the repository recursively.
56```
57git clone https://github.com/meganz/MEGAcmd.git
58cd MEGAcmd && git submodule update --init --recursive
59```
60
61## Building and installing
62
63For platforms with Autotools, MEGAcmd can be built and installed with:
64
65    sh autogen.sh
66    ./configure
67    make
68    make install
69
70* You will need to run `make install` as root
71
72`Note`: if you use a prefix in configure, autocompletion from non-interactive usage
73won't work. You would need to `source /YOUR/PREFIX/etc/bash_completion.d/megacmd_completion.sh`
74(or link it at /etc/bash_completion.d)
75
76Alternatively you can build using Qt project located at `contrib/QtCreator/MEGAcmd/MEGAcmd.pro`.
77
78For Windows/MacOS you will need to place the `3rdparty` folder (included in the dependency bundle referenced [`above`](#requirements)) into `sdk/bindings/qt/`.
79
80# Usage
81
82Before explaining the two ways of interaction, it is important to understand how MEGAcmd works. When you login with MEGAcmd, your session, the list of synced folders, and some cache database are stored in your local home folder. MEGAcmd also stores some other configuration in that folder. Closing it does not delete those and restarting your computer will restore your previous session (the same as megasync won't ask for user/password once you restart your computer).
83
84You will need to `logout` properly in order to clean your data.
85
86Now let's get into details of the two usage modes. Both modes require that MEGAcmdServer is running. You can manually launch it. Fortunately, you can also open the interactive shell or execute any command and the server will start automatically.
87
88## Interactively:
89
90Execute MEGAcmd shell. [`Platform`](#platforms) section explains how to do that in the different supported systems. You should be facing an interactive shell where you can start typing your commands, with their arguments and flags.
91
92You can list all the available commands with `help`.
93
94And obtain useful information about a command with `command --help`
95
96First you would like to log in into your account. Again, notice that doing this stores the session and other stuff in your home folder. A complete logout is required if you want to end you session permanently and clean any traces (see `logout --help` for further info).
97
98## Non-interactively:
99
100When MEGAcmd server is running, it will be listening for client commands. Use the different `mega-*` commands available.
101
102`mega-help` will list all these commands (you will need to prepend "mega-" to the commands listed there). To obtain further info use `mega-command --help`.
103
104Those commands will have an output value != 0 in case of failure.
105See [megacmd.h](https://github.com/meganz/MEGAcmd/blob/master/src/megacmd.h) to view the existing error codes.
106
107Ideally, you would like to have these commands in your `PATH` variable
108(See [`Platform`](#platforms) for more info). For further info use `mega-help --non-interactive`.
109
110## Usage examples
111
112Here are some examples of use (more info and usage examples are available at the [User Guide](UserGuide.md)).
113
114**Notice:** the commands listed here assume you are using the interactive interaction mode: they are supposed to be executed within MEGAcmdShell.
115
116
117* A **synchronization** can be established simply by typing:
118```
119sync /path/to/local/folder /folder/in/mega
120```
121This will synchronize the contents in your local and your mega folder both ways.
122
123* You can also set remote **backups** of a local folder to keep historical snapshots of your files. So simple as:
124```
125backup /path/mega/folder /remote/path --period="0 0 4 * * *" --num-backups=10
126```
127This will configure a backup of "myfolder" into /remote/path that will be carried out at 4:00 A.M. (UTC) every day. It will store the last 10 copies.
128
129 Further info on backups [here](contrib/docs/BACKUPS.md).
130
131* You **serve a location** in your MEGA account via WebDAV:
132```
133webdav /path/mega/folder
134```
135
136* Or **stream a file** in your MEGA account:
137```
138webdav /path/to/myfile.mp4
139```
140Further info on webdav and streaming [here](contrib/docs/WEBDAV.md).
141
142* **Download the contents** of a shared link:
143```
144get https://mega.nz/#F!ABcD1E2F!gHiJ23k-LMno45PqrSTUvw /path/to/local/folder
145```
146
147Now let's do something more complicated with non-interactive usage using some GNU tools (similar stuff can be easily done in Windows as well):
148
149* We want to provide something crypto secured with only 10 minutes of access:
150```
151mega-put /path/to/my/temporary_resource /exportedstuff/
152mega-export -a  /exportedstuff/temporary_resource --expire=10M | awk '{print $4}'
153```
154
155* Or imagine we'd like to public the enterprise promotional videos of May 2015 that we have previously stored in MEGA:
156```
157for i in $(mega-find /enterprise/video/promotional2015/may --pattern="*mpeg"); do
158mega-export -a $i | awk '{print $4}';
159done
160```
161
162# Platforms
163
164## Linux
165
166If you have installed MEGAcmd using one of the available packages at [here](https://mega.nz/cmd).
167
168Or have it built without `--prefix`, both the server (`mega-cmd-server`), the shell (`mega-cmd`) and the different client commands (`mega-*`) will be in your `PATH` (on a fresh install, you might need to open your terminal again).
169
170If you are using bash, you should also have autocompletion for client commands working.
171
172If that is not you case, include the location for the binaries in your `PATH` variable.
173
174
175## Windows
176You can have MEGAcmd installed using the installer from [here](https://mega.nz/cmd).
177
178If you are interested in installing MEGAcmd without human intervention, notice that this installer supports silent installation, you just need to execute in your command prompt:
179```
180MEGAcmdSetup.exe /S
181```
182
183Once you have MEGAcmd installed, you just need to execute it (via Desktop icon or Start Menu) to open the shell.  This will open MEGAcmdServer in the background (a process named MEGAcmdServer.exe).
184
185For a better user experience (specially in Windows 7) we recommend executing MEGAcmd from PowerShell.
186
187**Open PowerShell and execute:**
188
189```
190$env:PATH += ";$env:LOCALAPPDATA\MEGAcmd"
191MEGAcmdShell
192```
193
194For *non-interactive* usage, there are several `mega-*.bat`  client commands you can
195use writting their absolute paths, or including their location into your environment `PATH`
196 and execute them normally (`mega-*`).
197
198If you use PowerShell and you have installed the official MEGAcmd, you can do that simply with:
199
200```
201$env:PATH += ";$env:LOCALAPPDATA\MEGAcmd"
202```
203
204Client commands completion requires bash, hence, it is not available for Windows.
205
206### Caveats
207Although there have been several efforts in having non-ASCII unicode characters supported
208in Windows, there still may be some issues. Pay special attention if you are willing to use pipes or
209send the output of a command into a file from your client commands. See `help --unicode`
210for further info regarding that.
211
212## MacOS
213
214Install MEGAcmd from [here](https://mega.nz/cmd).
215
216For MacOS, after installing the dmg, you can launch the server using MEGAcmd in Applications. If you wish to use the client commands from MacOS Terminal, open the Terminal and include the installation folder in the `PATH`.
217
218**Typically:**
219
220```
221export PATH=/Applications/MEGAcmd.app/Contents/MacOS:$PATH
222```
223
224And for **bash completion**, source `megacmd_completion.sh`:
225
226```
227source /Applications/MEGAcmd.app/Contents/MacOS/megacmd_completion.sh
228```
229
230## NAS systems
231Currently we have build scripts for **Synology** and **QNAP**, which can be found in the `build/<system>` folder along with instructions on how to set up the build.  Typically this results in a 'package' which can then be manually installed in the NAS.   To use MEGAcmd on those systems, ssh into the device and run the commands as normal (having first added their folder to your `PATH` variable).
232
233*Important note for MacOS Catalina or above: since Catalina, MacOS uses `zsh` as default shell. If you want to have auto completion, we strongly recommend you to use `bash` shell (just execute `bash` in your terminal).
234
235# Features:
236
237## Autocompletion:
238
239MEGAcmd features autocompletion in both interactive and non-interactive (only for bash) mode. It will help completing both local and remote (Mega Cloud) files, flags for commands, values for flags/access levels, even contacts.
240
241## Verbosity
242There are two different kinds of logging messages:
243- **SDK based**: those messages reported by the sdk and dependent libraries.
244- **MEGAcmd based**: those messages reported by MEGAcmd itself.
245
246You can adjust the level of logging for those kinds with `log` command.
247
248However, passing `-v` (`-vv`, `-vvv`, and so on for a more verbose output)
249to an specific command will use higher level of verbosity of MEGAcmd based messages.
250
251Further info on verbosity [here](contrib/docs/DEBUG.md).
252
253## Regular Expressions
254If you have compiled MEGAcmd with PCRE (enabled by default), you can use PCRE compatible expressions in certain commands with the flag `--use-pcre`. Otherwise, if compiled with c++11, c++11 regular expressions will be used.
255
256 If none of the above is the case, you can only use wildcards: "*" for any number of characters or "?" for a single unknown character.
257
258You can check the regular expressions compatibility with `find --help`:
259```
260find --help
261...
262Options:
263 --pattern=PATTERN	Pattern to match (Perl Compatible Regular Expressions)
264```
265
266**Notice:** if you use MEGAcmd in non interactive mode, notice that shell pattern will take precedence. You will need to either escape symbols like `*` (`\*`) or surround them between quotes (e.g: "*.txt").
267
268## MEGAcmd Updates
269
270MEGAcmd updates automatically for Windows & MacOS.
271
272For Linux, whenever there is a new update, it will be published in the corresponding repository and your system's updating tool will let you update it.
273
274### Disable automatic updates
275
276You can type `update --auto=OFF` to disable automatic updates. `update --auto=ON` will re-enable them.
277
278If you want to see the state of automatic updates you can use `update --auto=query`. This will inform if automatic updates are enabled or not.
279
280Notice that MEGAcmdServer must be running in order to have automatic updates working.
281
282You can also update manually by typing `update` within MEGAcmd. This will check if there are updates available and proceed to update if affirmative. Whenever MEGAcmd is updated it will be restarted (all open instances of MEGAcmdShell will be restarted too).
283
284Alternatively you can also execute `MEGAcmdUpdater.exe` in Windows or `MEGAcmdUpdater` (located at /Applications/MEGAcmd.app/Contents/MacOS) in MacOS.
285
286## Known Bugs
287
288Currently there are certain discrepancies with **PATHS** when logging into a public folder.
289
290For instance, imagine a folder named `toshare` with a subfolder named `x`. If we login in to `toshare` and execute `find /x`, this will be the output:
291
292```
293/toshare/x
294```
295
296Whereas if we execute `find /toshare/x`, we receive an error, since folder absolute path
297refers to `/` as root path.
298
299```
300[err: 12:21:51] Couldn't find /toshare/x
301```
302
303It might better be referred as `/toshare/x`.
304