在 ADLS 上自动激活 SFTP

问题描述 投票:0回答:1

我有一个 Azure 数据湖存储帐户。在 Azure Web 界面上,我可以激活或停用 SFTP :

我可以使用 python 激活或停用 SFTP 吗?

我发现了一些使用吟游诗人的东西,但这不起作用:

from azure.storage.filedatalake import ADLSFileSystemClient

client = ADLSFileSystemClient.from_connection_string("connection_string")

client.set_sftp_access("my-filesystem", True)

错误:

ImportError:无法从“azure.storage.filedatalake”导入名称“ADLSFileSystemClient”(lib/python3.8/site-packages/azure/storage/filedatalake/init.py)

python azure automation sftp
1个回答
0
投票

是否可以使用 Python 激活或停用 SFTP?

您可以使用以下代码通过 Azure Python SDK

 Enable and disable
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

enter image description here

enter image description here

同样,在上面的代码中,如果您更改

storage_account.is_sftp_enabled=False
,它将禁用 Azure 存储帐户中的 SFTP。

参考:

azure.mgmt.storage.StorageManagementClient 的 Python 示例 (programcreek.com)

© www.soinside.com 2019 - 2024. All rights reserved.