Azure Files Sample Code Repository
Welcome to the Azure Files sample code repository. This page provides a curated collection of code samples demonstrating various functionalities of Azure Files, including mounting, file operations, and management tasks.
Getting Started
Before diving into the samples, ensure you have an Azure subscription and an Azure Storage account with Azure Files enabled. You can create these resources through the Azure portal.
Key Concepts:
- Azure Files: Fully managed cloud file shares accessible via the SMB and NFS protocols.
- Storage Account: A container for all your Azure Storage data objects.
- File Share: A scalable, cloud-based file share.
- Mounting: Connecting to your Azure File Share from various operating systems (Windows, Linux, macOS).
Featured Samples
Mounting Azure Files on Windows (SMB)
Learn how to mount an Azure File Share on a Windows machine using the SMB protocol. This sample includes PowerShell and command-line instructions.
View SampleMounting Azure Files on Linux (SMB)
Discover how to mount an Azure File Share on a Linux distribution using the SMB protocol. This sample covers commands for common Linux environments.
View SampleMounting Azure Files on macOS (SMB)
This sample guides you through mounting an Azure File Share on macOS using SMB. It includes instructions for Terminal commands.
View SampleAzure Files REST API Operations
Explore how to interact with Azure Files using its REST API. This sample demonstrates common operations like creating, listing, and deleting shares.
View SampleAzure CLI for File Share Management
Learn to manage Azure File Shares using the Azure Command-Line Interface (CLI). This sample covers creating, deleting, and configuring shares.
View SampleAzure SDK for Python - File Operations
A practical example using the Azure SDK for Python to perform file operations within an Azure File Share, such as uploading and downloading files.
# Example: Uploading a file
from azure.storage.fileshare import ShareServiceClient
connect_str = "YOUR_AZURE_STORAGE_CONNECTION_STRING"
share_name = "myshare"
file_path = "local/path/to/your/file.txt"
destination_file_name = "remote/file.txt"
# Create the ShareServiceClient object
share_service_client = ShareServiceClient.from_connection_string(connect_str)
# Get a client to the share
share_client = share_service_client.get_share_client(share_name)
# Get a client to the root directory
share_directory_client = share_client.get_directory_client("")
# Upload the file
with open(file_path, "rb") as fh:
share_directory_client.upload_file(destination_file_name, fh)
print(f"File '{file_path}' uploaded to '{share_name}/{destination_file_name}'")
View Full Sample
Contribution and Feedback
We encourage contributions to this repository. If you have a useful sample or find an issue, please consider submitting a pull request or opening an issue on our GitHub repository.