我有一个 Azure datalake 存储帐户。在 Azure Web 界面上,我可以激活或停用 SFTP :
我可以使用 python 激活或停用 SFTP 吗?
我发现了一些使用 Bard 的东西,但它不起作用:
from azure.storage.filedatalake import ADLSFileSystemClient
client = ADLSFileSystemClient.from_connection_string("connection_string")
client.set_sftp_access("my-filesystem", True)
错误:
ImportError: cannot import name 'ADLSFileSystemClient' from 'azure.storage.filedatalake' (lib/python3.8/site-packages/azure/storage/filedatalake/init.py)
最佳答案
Is there a possibility to activate or deactivate SFTP using Python?
您可以使用以下代码通过 Azure Python SDK 来启用和禁用
SFTP。
代码:(启用)
from azure.mgmt.storage import StorageManagementClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
subscription_id="Your-subscription-id"
storage_client = StorageManagementClient(credential, subscription_id)
resource_group_name = "your-resource-grp-name"
storage_account_name = "your-storage-account-name"
credential = DefaultAzureCredential()
storage_client = StorageManagementClient(credential, subscription_id)
# Get the current 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
updated_storage_account=storage_client.storage_accounts.update(
resource_group_name, storage_account_name, storage_account
)
print("Updated Storage Account Properties:")
print(f"Name: {updated_storage_account.name}")
print(f"Is SFTP Enabled: {updated_storage_account.is_sftp_enabled}")
输出:
Updated Storage Account Properties:
Name: venkat098
Is SFTP Enabled: True
同样,在上面的代码中,如果您更改storage_account.is_sftp_enabled=False
,它将禁用 Azure 存储帐户中的 SFTP。
引用:
Python Examples of azure.mgmt.storage.StorageManagementClient (programcreek.com)
关于python - 在 ADLS 上自动激活 SFTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76970855/