MEGAcmd4J

MEGAcmd for Java

MEGAcmd for Java

Build Status Maven Central Twitter URL

This is an open source Java library for the mega.nz API, working on top of the MEGAcmd CLI. There is a Quick Start available for developers who want to start using the library right away.

Features

Feature MEGAcmd Description
Start session login Allows to authenticate into the mega api to start running commands using user and password, or sessionID or an exported/public folder
Close session logout Close the current session.
Put content in the Cloud put Upload content to the cloud.
Session Id session Returns the id of the current session.
HTTPS https Shows if HTTPS is used for transfers. Allows enabling and disabling this option.
Idenfity current username whoami Returns the username of the current session.
Make directory mkdir Creates a directory or multiple based on a given remote path.
List files/directories ls List files and directories in a remote path.
Get content get Get the content of files and directories in a remote path.
Copy cp Copy remote files and directories into a new location.
Move mv Move remote files and directories into a new location.
Change password passwd Changes the password of the currently logged user.
Shares folder share Shares/Unshares folder with user
Export to the Internet export Create, delete or list existing public links
Signup user signup Register as user with a given email

If you have any doubt about how each feature works, please run

    MegaClient <MEGAcmd> --help

Additional Features

This features have no corresponding Megacmd command, but they are infered from the existing ones

Count

Show the amount of elements in a folder or that match the query mask. E.g.

    final long amountOfFilesAndDirectories = sessionMega.count("remote/path");

But what if you want to filter that counting and it a Predicate to, for instance, just get the files and not the directories.

    final long amountOfFiles = sessionMega.count("remote/path", FileInfo::isFile);

Exists

This is pretty much the equivalent of java.io.File.exists. It checks if the remote path or mask indicates any non null response. E.g.

    sessionMega.exists("remote/path/filesprefix*.ext");

System requirements

Environment variables to set

Setup your credentials

  1. The most common way to setup your credentials would be using environment variables MEGA_EMAIL and MEGA_PWD.

  2. Use an existing session can be a saver way. You can use it from your app as long as it don’t be closed.

Continuous Integrations

As most OSS projects in github this one uses Travis CI. I you want a CLI for your project, its recommend to install the correspondent ruby gem:

    gem install travis

Code style

Known Bugs

There were tests that moved a file to a folder where another file with the same name was present. In Windows boths files were identified as one and when I ran a move instruction for that file name it operated over the last moved file and left the oldest one in that folder. In Linux both files are keep in the folder but identified as different ones, even if the properties where the same; when a move operation was run over such filename it operated over both.

Also when I tested this on Windows I got more detailed error code, which also gives more detailed exceptions.

I suppose these issues has to do with the libraries used for making calls to the Mega API, because in the Linux version I had more features enabled that in the Windows one, whilst the Mega Cmd and SDK version were the same. It has already been reported as an issue in the MEGAcmd project. It was afterwards solved by keeping return errors always positive to be compliant with POSIX standard. Thats why an issue was raised in this repository to provide support for this new feature.

More information

Status

Pre-release or Beta: The project has gone through multiple rounds of active development with a goal of reaching a stable release version, but is not there yet.

Path of Development: Active (November 4th 2018)

Author

License

This project is licensed under the MIT License - see the LICENSE.md file for details