Skip to content

Open Source Java library for the mega.co.nz API using the MEGAcmd CLI

License

Notifications You must be signed in to change notification settings

junkerjoerg12/MEGAcmd4J

 
 

Repository files navigation

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
Version version Prints MEGAcmd versioning and extra info
Quit quit Quits MEGAcmd. Stops the server without killing the session
Import import Imports the contents of a remote link into user's cloud

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");

Export with an expiration date

With a premium mega account, you can export and generate public folder links by setting the option expire date.

    LocalDate expireDate = LocalDate.of(2020, 9, 2);
    final ExportInfo exportInfo = sessionMega.export(exportFolder)
            .setExpireDate(expireDate)
            .call();

or you can just specify a duration using TimeDelay.

    final ExportInfo exportInfo = sessionMega.export(exportFolder)
        .setExpirationTimeDelay(TimeDelay.of(
             Period.ofYears(3).plusMonths(11).plusDays(15)
         ))
        .call();

MEGAcmdServer

Thanks to the class io.github.eliux.mega.MegaServer you can now start and stop the local MEGAcmdServer on command.

System requirements

  • Install MEGAcmd. Available packages for MEGAcmd in all supported platforms should be found here.

Environment variables to set

  • MEGA_EMAIL: Email used as username (lowercase)
  • MEGA_PWD: Corresponding password
  • CMD_TTL_ENV_VAR: Maximum time to live of a running MEGAcmd command. By default, 20 seconds.

Setup your credentials

  1. The most common way to setup your credentials would be using the 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

For users

  • Once installed MEGAcmd in your system, execute mega-help to check all commands. You will be able to notice those who are already implemented in this library and those who don't. Try them out.

Contributing

Make sure your contact data is included in the Contributors section, and

Contributors

Add your name, email and your account for Twitter, Github or LinkedIn:

Built With

  • Java SDK 8 - Java™ Platform
  • Maven - Dependency Management
  • MEGAcmd - Command Line Interactive and Scriptable Application

Author

License

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

About

Open Source Java library for the mega.co.nz API using the MEGAcmd CLI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.5%
  • Other 0.5%