File Browser#
List#
- FileBrowser.listdir(path, depth=None, include_deleted=False)
List Directory
- Parameters:
path (str) – Path
include_deleted (bool,optional) – Include deleted files, defaults to False
with GlobalAdmin('tenant.ctera.com') as admin:
admin.login('admin-user', 'admin-pass')
admin.files.listdir('Users/John Smith/My Files')
admin.files.listdir('Users/John Smith/My Files', include_deleted=True) # include deleted files
with ServicesPortal('tenant.ctera.com') as user:
user.login('username', 'user-password')
user.files.listdir('My Files/Documents')
user.files.listdir('My Files/Documents', include_deleted=True) # include deleted files
- FileBrowser.walk(path, include_deleted=False)
Walk Directory Contents
- Parameters:
path (str) – Path to walk
include_deleted (bool,optional) – Include deleted files, defaults to False
with GlobalAdmin('tenant.ctera.com') as admin:
admin.login('admin-user', 'admin-pass')
for element in admin.files.walk('Users/John Smith/My Files'):
print(element.name) # traverse John Smith's 'My Files' directory and print the name of all files and folders
with ServicesPortal('tenant.ctera.com') as user:
user.login('username', 'user-password')
for element in user.files.walk('My Files/Documents'):
print(element.name) # as a user, traverse all and print the name of all files and folders in 'My Files/Documents'
Snapshots#
- FileBrowser.list_snapshots(path)
List snapshots of a file or directory
- Parameters:
path (str) – Path to the file or directory
- Returns:
List of snapshots, each containing: - startTimestamp: When the snapshot was created - calculatedTimestamp: When the snapshot was processed - current: Whether this is the current version - url: The URL path to access this snapshot’s contents
- Return type:
list[dict]
with GlobalAdmin('tenant.ctera.com') as admin:
admin.login('admin-user', 'admin-pass')
# List all snapshots for a path
snapshots = admin.files.list_snapshots('Users/John Smith/My Files')
for snapshot in snapshots:
print(f"Snapshot from: {snapshot.startTimestamp}")
print(f"URL: {snapshot.url}")
# Access files in this snapshot using listdir
files = admin.files.listdir(f"{snapshot.url}")
Download#
- FileBrowser.download(path, destination=None)
Download a file
- Parameters:
path (str) – Path
destination (str,optional) – File destination, if it is a directory, the original filename will be kept, defaults to the default directory
"""When logged in as a Global Administrator"""
admin.files.download('Users/John Smith/My Files/Documents/Sample.docx')
"""When logged in as a tenant user or admin"""
user.files.download('Users/John Smith/My Files/Documents/Sample.docx')
- FileBrowser.download_as_zip(cloud_directory, files, destination=None)
Download a list of files and/or directories from a cloud folder as a ZIP file
Warning
The list of files is not validated. The ZIP file will include only the existing files and directories
- Parameters:
cloud_directory (str) – Path to the cloud directory
files (list[str]) – List of files and/or directories in the cloud folder to download
destination (str,optional) – File destination, if it is a directory, the original filename will be kept, defaults to the default directory
"""When logged in as a Global Administrator"""
admin.files.download_as_zip('Users/John Smith/My Files/Documents', ['Sample.docx', 'Wizard Of Oz.docx'])
"""When logged in as a tenant user or admin"""
user.files.download_as_zip('Users/John Smith/My Files/Documents', ['Sample.docx', 'Wizard Of Oz.docx'])
Copy#
- FileBrowser.copy(*paths, destination=None)
Copy one or more files or folders
- Parameters:
paths (list[str]) – List of paths
destination (str) – Destination
user.files.copy(*['My Files/Documents/Sample.docx', 'My Files/Documents/Burndown.xlsx'], destination='The/quick/brown/fox')
Create Public Link#
- FileBrowser.public_link(path, access='RO', expire_in=30)
Create a public link to a file or a folder
- Parameters:
path (str) – The path of the file to create a link to
access (str,optional) – Access policy of the link, defaults to ‘RO’
expire_in (int,optional) – Number of days until the link expires, defaults to 30
"""
Access:
- RW: Read Write
- RO: Read Only
- NA: No Access
"""
"""Create a Read Only public link to a file that expires in 30 days"""
user.files.public_link('My Files/Documents/Sample.docx')
"""Create a Read Write public link to a folder that expires in 45 days"""
user.files.public_link('My Files/Documents/Sample.docx', 'RW', 45)
Create Directories#
- CloudDrive.mkdir(path)
Create a new directory
- Parameters:
path (str) – Directory path
"""When logged in as a Global Administrator"""
admin.files.mkdir('Users/John Smith/My Files/Documents')
"""When logged in as a tenant user or admin"""
user.files.mkdir('My Files/Documents')
- CloudDrive.makedirs(path)
Create a directory recursively
- Parameters:
path (str) – Directory path
"""When logged in as a Global Administrator"""
admin.files.makedirs('Users/John Smith/My Files/The/quick/brown/fox')
"""When logged in as a tenant user or admin"""
user.files.makedirs('The/quick/brown/fox')
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
"""When logged in as a Global Administrator"""
admin.files.rename('Users/John Smith/My Files/Documents/Sample.docx', 'Wizard Of Oz.docx')
"""When logged in as a tenant user or admin"""
user.files.makedirs('My Files/Documents/Sample.docx', 'Wizard Of Oz.docx')
Delete#
- CloudDrive.delete(*paths)
Delete one or more files or folders
- Parameters:
path (str) – Path
"""When logged in as a Global Administrator"""
admin.files.delete(*['Users/John Smith/My Files/Documents/Sample.docx', 'Users/John Smith/My Files/Documents/Wizard Of Oz.docx'])
"""When logged in as a tenant user or admin"""
user.files.delete(*['My Files/Documents/Sample.docx', 'My Files/Documents/Wizard Of Oz.docx'])
Undelete#
- CloudDrive.undelete(*paths)
Recover one or more files or folders
- Parameters:
path (str) – Path
"""When logged in as a Global Administrator"""
admin.files.undelete(*['Users/John Smith/My Files/Documents/Sample.docx', 'Users/John Smith/My Files/Documents/Wizard Of Oz.docx'])
"""When logged in as a tenant user or admin"""
user.files.undelete(*['My Files/Documents/Sample.docx', 'My Files/Documents/Wizard Of Oz.docx'])
Move#
- CloudDrive.move(*paths, destination=None)
Move one or more files or folders
- Parameters:
paths (list[str]) – List of paths
destination (str) – Destination
"""When logged in as a Global Administrator"""
admin.files.move(*['Users/John Smith/My Files/Documents/Sample.docx', 'Users/John Smith/My Files/Documents/Wizard Of Oz.docx'], destination='Users/John Smith/The/quick/brown/fox')
"""When logged in as a tenant user or admin"""
user.files.move(*['My Files/Documents/Sample.docx', 'My Files/Documents/Wizard Of Oz.docx'], destination='The/quick/brown/fox')
Upload#
- CloudDrive.upload(path, destination)#
Upload a file
- Parameters:
path (str) – Local path
destination (str) – Remote path
"""When logged in as a Global Administrator"""
admin.files.upload(r'C:\Users\admin\Downloads\Tree.jpg', 'Users/John Smith/My Files/Images')
"""Uploading as a tenant user or admin"""
user.files.upload(r'C:\Users\admin\Downloads\Tree.jpg', 'My Files/Images')
Managing S3 Credentials#
Starting CTERA 8.0, CTERA Portal features programmatic access via the S3 protocol, also known as CTERA Fusion For more information on how to enable CTERA Fusion and the supported extensions of the S3 protocol, please refer to the following article <https://kb.ctera.com/v1/docs/en/setting-up-access-from-an-s3-browser>.
The following section includes examples on how to instantiate an S3 client using the Amazon SDK for Python (boto3).
credentials = user.credentials.s3.create() # if logged in as a user
# credentials = admin.credentials.s3.create(core_types.UserAccount('username', 'domain')) # if logged in as a Global Admin
"""Instantiate the boto3 client"""
client = boto3.client(
's3',
endpoint_url=https://domain.ctera.com:8443, # your CTERA Portal tenant domain
aws_access_key_id=credentials.accessKey,
aws_secret_access_key=credentials.secretKey,
verify=False # disable certificate verification (Optional)
)
"""List Buckets"""
response = client.list_buckets()
for bucket in response['Buckets']:
print(bucket['Name'])
"""Upload a file"""
client.upload_file(r'./document.docx', 'my-bucket-name', 'data-management-document.docx')
"""List files"""
response = client.list_objects_v2(Bucket='my-bucket-name')
for item in response['Contents']:
print(item['Key'], item['LastModified'])
"""List files, using Pagination"""
paginator = client.get_paginator('list_objects_v2')
for page in paginator.paginate(Bucket='my-bucket-name'):
for item in page['Contents']:
print(item['Key'], item['LastModified'])
"""Download a file"""
client.download_file(r'./data-management-document.docx', 'my-bucket-name', 'data-management-document-copy.docx')
# for more information, please refer to the Amazon SDK for Python (boto3) documentation.