Azure / blobxfer

Azure Storage transfer tool and data movement library
MIT License
151 stars 38 forks source link

How to download an entire directory from a Fileshare #129

Closed jrcorralesf closed 3 years ago

jrcorralesf commented 3 years ago

I'm trying to download a entire directory from a Fileshare with the following function inside a class that receives the account_name, account_key, endpoint and share_name (fileshare name): (all in python-Django) `def download_folder_blobxfer(self, folder_path):

    # construct general options
    time_out=blobxfer.api.TimeoutOptions(20,200,2)
    concurrency=blobxfer.api.ConcurrencyOptions(0,0,0,0,1)
    general_options = blobxfer.api.GeneralOptions(concurrency, timeout=time_out)
    class RestoreFileProperties(object):
        def __init__(self,attributes,lmt):
            self.attributes=attributes
            self.lmt=lmt

    # construct download options
    download_options = blobxfer.api.DownloadOptions(
        False,
        8388608,
        False,
        False,
        3,
        StorageModes(40),
        True,
        True,
        False,
        RestoreFileProperties(False,False),
        None,
        1 )

    # construct skip on options
    skip_on_options = blobxfer.api.SkipOnOptions(
        False,
        False,
        False )

    # construct local destination path
    local_destination_path = blobxfer.api.LocalDestinationPath(os.getcwd())

    # construct specification
    specification = blobxfer.api.DownloadSpecification(
        download_options,
        skip_on_options,
        local_destination_path)

    # construct credentials
    credentials = blobxfer.api.AzureStorageCredentials(general_options)
    credentials.add_storage_account(self.account_name, self.account_key, self.endpoint)

    # construct Azure source paths and add it to specification
    storage_account=credentials.get_storage_account(self.account_name)
    azure_path = blobxfer.api.AzureSourcePath()
    entire_path=f'{self.share_name}/{folder_path}'
    azure_path.add_path_with_storage_account(entire_path, storage_account)
    specification.add_azure_source_path(azure_path)

    # execute downloader
    downloader = blobxfer.api.Downloader(
        general_options,
        credentials,
        specification)
    downloader.start()`

but when i try this, i get the following traceback: <blobxfer.operations.azure.StorageAccount object at 0x0000020BD160CBE0> Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 870, in start self._run() File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 706, in _run blobxfer.operations.download.Downloader.ensure_local_destination( File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 146, in ensure_local_destination sa = creds.get_storage_account( File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\azure\__init__.py", line 84, in get_storage_account return self._storage_accounts[name] KeyError: <blobxfer.operations.azure.StorageAccount object at 0x0000020BD160CBE0> Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\rest_framework\views.py", line 502, in dispatch response = handler(request, *args, **kwargs) File "C:\Users\julia\Documents\PROYECTOS INTEREDES\CRM-INTEREDES\sdkv2\crm-backend\core_fileadmin\infrastructure\viewsets\static.py", line 24, in get fileadmin = ConnectionStorageFactory().get_adminer("azure") File "C:\Users\julia\Documents\PROYECTOS INTEREDES\CRM-INTEREDES\sdkv2\crm-backend\core_fileadmin\application\connection.py", line 25, in __init__ "azure": AzureAdminer(**azure_settings), File "C:\Users\julia\Documents\PROYECTOS INTEREDES\CRM-INTEREDES\sdkv2\crm-backend\core_fileadmin\application\services\azure.py", line 32, in __init__ self.download_folder_blobxfer(folder_path) File "C:\Users\julia\Documents\PROYECTOS INTEREDES\CRM-INTEREDES\sdkv2\crm-backend\core_fileadmin\application\services\azure.py", line 111, in download_folder_blobxfer downloader.start() File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 885, in start raise ex File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 870, in start self._run() File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 706, in _run blobxfer.operations.download.Downloader.ensure_local_destination( File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\download.py", line 146, in ensure_local_destination sa = creds.get_storage_account( File "C:\ProgramData\Anaconda3\envs\crm\lib\site-packages\blobxfer\operations\azure\__init__.py", line 84, in get_storage_account return self._storage_accounts[name] KeyError: <blobxfer.operations.azure.StorageAccount object at 0x0000020BD160CBE0>

I appreciate any help

alfpark commented 3 years ago

You are attempting to invoke add_path_with_storage_account with a StorageAccount object and not by name (str).