python - 在 ADLS 上自动激活 SFTP

标签 python azure automation sftp

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

我可以使用 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

enter image description here

enter image description here

同样,在上面的代码中,如果您更改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/

相关文章:

json - 从azure逻辑应用程序中的JSON对象文件返回特定属性(文本)

ssh - 如何在 MobaXterm 中打开 session 时自动启动隧道?

python - 类成员也在Python中创建实例成员

Python有没有相当于__init__()的shutdown

node.js - 在 Node.js 机器人服务中实现 Redis

azure - 从 Azure 资源管理器模板中的资源组获取标签

Excel 2003 VBA - 复制此选择和着色行的代码的方法

python - Pip 在 Anaconda Python 中搞砸了

c# - HttpWebRequest 在第二次调用 Web 服务器时超时

c# - 在 ASP Net Core 中实现两个身份验证选项( token 和证书)