File Browser

File Browser

List

FileBrowser.ls(path, include_deleted=False)

Execute ls on the provided path

Parameters
  • path (str) – Path to list

  • include_deleted (bool,optional) – Include deleted files, defaults to False

file_browser.ls('')  # List the contents of the Cloud Drive

file_browser.ls('My Files')  # List the contents of the 'My Files' folder

file_browser.ls('My Files', True)  # Include deleted files
FileBrowser.walk(path, include_deleted=False)

Perform walk on the provided path

Parameters
  • path (str) – Path to perform walk on

  • include_deleted (bool,optional) – Include deleted files, defaults to False

file_browser.walk('My Files')

Download

FileBrowser.download(path, destination=None)

Download a file

Parameters
  • path (str) – Path of the file to download

  • destination (str,optional) – File destination, if it is a directory, the original filename will be kept, defaults to the default directory

file_browser.download('My Files/Documents/Sample.docx')

Copy

FileBrowser.copy(src, dest)

Copy a file or directory

Parameters
  • src (str) – The source path of the file or directory

  • dst (str) – The destination path of the file or directory

file_browser.copy('My Files/Documents/Sample.docx', 'The/quick/brown/fox')
FileBrowser.copy_multi(src, dest)
file_browser.copy_multi(['My Files/Documents/Sample.docx', 'My Files/Documents/Burndown.xlsx'], 'The/quick/brown/fox')

Cloud Drive

The CloudDrive class is a subclass to cterasdk.common.files.browser.FileBrowser providing file access to the user’s Cloud Drive

from getpass import getpass

"""Accessing Cloud Drive Files and Folders as a Global Administrator"""
admin = GlobalAdmin('portal.ctera.com')  # logging in to /admin
admin.login('admin', getpass())
file_browser = admin.files # the field is an instance of CloudDrive class object

"""Accessing Cloud Drive Files and Folders as a Tenant User Account"""
user = ServicesPortal('portal.ctera.com')  # logging in to /ServicesPortal
user.login('bwayne', getpass())
file_browser = user.files # the field is an instance of CloudDrive class object

Create Directory

CloudDrive.mkdir(path, recurse=False)

Create a new directory

Parameters
  • path (str) – Path of the directory to create

  • recurse (bool,optional) – Whether to create the path recursivly, defaults to False

file_browser.mkdir('My Files/Documents')

file_browser.mkdir('The/quick/brown/fox', recurse = True)

Rename

CloudDrive.rename(path, name)

Rename a file

Parameters
  • path (str) – Path of the file or directory to rename

  • name (str) – The name to rename to

file_browser.rename('My Files/Documents/Sample.docx', 'Wizard Of Oz.docx')

Delete

CloudDrive.delete(path)

Delete a file

Parameters

path (str) – Path of the file or directory to delete

file_browser.delete('My Files/Documents/Sample.docx')
CloudDrive.delete_multi(*args)

Delete multiple files and/or directories

Parameters

*args – Variable lengthed list of paths of files and/or directories to delete

file_browser.delete_multi('My Files/Documents/Sample.docx', 'The/quick/brown/fox')

Undelete

CloudDrive.undelete(path)

Restore a previously deleted file or directory

Parameters

path (str) – Path of the file or directory to restore

file_browser.undelete('My Files/Documents/Sample.docx')
CloudDrive.undelete_multi(*args)

Restore previously deleted multiple files and/or directories

Parameters

*args – Variable length list of paths of files and/or directories to restore

file_browser.undelete_multi('My Files/Documents/Sample.docx', 'The/quick/brown/fox')

Move

CloudDrive.move(src, dest)

Move a file or directory

Parameters
  • src (str) – The source path of the file or directory

  • dst (str) – The destination path of the file or directory

file_browser.move('My Files/Documents/Sample.docx', 'The/quick/brown/fox')
CloudDrive.move_multi(src, dest)
file_browser.move_multi(['My Files/Documents/Sample.docx', 'My Files/Documents/Burndown.xlsx'], 'The/quick/brown/fox')

Upload

CloudDrive.upload(file_path, server_path)

Upload a file

Parameters
  • file_path (str) – Path to the local file to upload

  • server_path (str) – Path to the directory to upload the file to

"""
Upload the 'Tree.jpg' file as an End User to 'Forest' directory
"""
file_browser.files.upload(r'C:\Users\BruceWayne\Downloads\Tree.jpg', 'Images/Forest')

"""
Upload the 'Tree.jpg' file as an Administrator to an End User's Cloud Drive
"""
file_browser.files.upload(r'C:\Users\Administrator\Downloads\Tree.jpg', 'Bruce Wayne/Images/Forest')

Collaboration Shares

CloudDrive.share(path, recipients, as_project=True, allow_reshare=True, allow_sync=True)

Share a file or a folder

Parameters
  • path (str) – The path of the file or folder to share

  • recipients (list[cterasdk.core.types.ShareRecipient]) – A list of share recipients

  • as_project (bool,optional) – Share as a team project, defaults to True when the item is a cloud folder else False

  • allow_reshare (bool,optional) – Allow recipients to re-share this item, defaults to True

  • allow_sync (bool,optional) – Allow recipients to sync this item, defaults to True when the item is a cloud folder else False

Returns

A list of all recipients added to the collaboration share

Return type

list[cterasdk.core.types.ShareRecipient]

"""
Share with a local user and a local group.
- Grant the local user with read only access for 30 days
- Grant the local group with read write access with no expiration
"""

alice = portal_types.UserAccount('alice')
engineers = portal_types.GroupAccount('Engineers')

recipients = []

alice_rcpt = portal_types.ShareRecipient.local_user(alice).expire_in(30).read_only()
engineers_rcpt = portal_types.ShareRecipient.local_group(engineering).read_write()

file_browser.share('Codebase', [alice_rcpt, engineers_rcpt])
"""
Share with an external recipient
- Grant the external user with preview only access for 10 days
"""
jsmith = portal_types.ShareRecipient.external('jsmith@hotmail.com').expire_in(10).preview_only())
file_browser.share('My Files/Projects/2020/ProjectX', [jsmith])

"""
Share with an external recipient, and require 2 factor authentication
- Grant the external user with read only access for 5 days, and require 2 factor authentication over e-mail
"""
jsmith = portal_types.ShareRecipient.external('jsmith@hotmail.com', True).expire_in(5).read_only())
file_browser.share('My Files/Projects/2020/ProjectX', [jsmith])
"""
Share with a domain groups
- Grant the Albany domain group with read write access with no expiration
- Grant the Cleveland domain group with read only access with no expiration
"""
albany_group = portal_types.GroupAccount('Albany', 'ctera.com')
cleveland_group = portal_types.GroupAccount('Cleveland', 'ctera.com')

albany_rcpt = portal_types.ShareRecipient.domain_group(albany_group).read_write()
cleveland_rcpt = portal_types.ShareRecipient.domain_group(cleveland_group).read_only()

file_browser.share('Cloud/Albany', [albany_rcpt, cleveland_rcpt])
CloudDrive.add_share_recipients(path, recipients)

Add share recipients

Parameters
Returns

A list of all recipients added

Return type

list[cterasdk.core.types.ShareRecipient]

Note

if the share recipients provided as an argument already exist, they will be skipped and not updated

CloudDrive.remove_share_recipients(path, accounts)

Remove share recipients

Parameters
Returns

A list of all share recipients removed

Return type

list[cterasdk.core.types.PortalAccount]

CloudDrive.unshare(path)

Unshare a file or a folder

"""
Unshare a file or a folder
"""
file_browser.unshare('Codebase')
file_browser.unshare('My Files/Projects/2020/ProjectX')
file_browser.unshare('Cloud/Albany')

Backups

The Backups class is a subclass to cterasdk.common.files.browser.FileBrowser providing access to files stored in backup folders

from getpass import getpass

"""Accessing Backups as a Global Administrator"""
admin = GlobalAdmin('portal.ctera.com')  # logging in to /admin
admin.login('admin', getpass())
file_browser = admin.files # the field is an instance of Backups class object

"""Accessing Backups as a Tenant User Account"""
user = ServicesPortal('portal.ctera.com')  # logging in to /ServicesPortal
user.login('bwayne', getpass())
file_browser = user.backups  # the field is an instance of Backups class object