Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Last active January 18, 2024 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalgjose/6b0a0127092552a32493271fb59ef7f5 to your computer and use it in GitHub Desktop.
Save amalgjose/6b0a0127092552a32493271fb59ef7f5 to your computer and use it in GitHub Desktop.
Python program to programatically enable or disable SFTP in an Azure storage account (Azure Blob Storage)
from azure.mgmt.storage import StorageManagementClient
from azure.identity import ClientSecretCredential
# Update the below variables with the correct values
subscription_id="Your-subscription-id"
resource_group_name = "your-resource-grp-name"
storage_account_name = "your-storage-account-name"
# Update the below variables with the Service Principle credentials.
AZURE_CLIENT_ID = ""
AZURE_CLIENT_SECRET = ""
AZURE_TENANT_ID = ""
credential = ClientSecretCredential(
client_id=AZURE_CLIENT_ID,
client_secret=AZURE_CLIENT_SECRET,
tenant_id=AZURE_TENANT_ID)
storage_client = StorageManagementClient(credential, subscription_id)
# Retrieve the properties of the storage account
storage_account = storage_client.storage_accounts.get_properties(
resource_group_name, storage_account_name
)
# Enable SFTP for the storage account
storage_account.is_sftp_enabled=True
modified_storage_account=storage_client.storage_accounts.update(
resource_group_name, storage_account_name, storage_account
)
print("<--The Properties of the Modified Storage Account are given below:-->")
print(f"Storage Account Name: {modified_storage_account.name}")
print(f"SFTP Status: {modified_storage_account.is_sftp_enabled}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment