【问题标题】:Create an Azure Website with PowerShell and FTP使用 PowerShell 和 FTP 创建 Azure 网站
【发布时间】:2014-12-30 06:51:51
【问题描述】:

我需要编写一个自动创建 Azure 网站并部署本地文件系统内容的 PowerShell 脚本。似乎 Azure PowerShell SDK 没有提供将文件复制到网站的方法,因此我们希望使用 FTP 作为部署方法。

要获得正确的 FTP 端点和凭据,我发现的唯一方法是调用 Azure Management Rest API:Get a Site’s Publish Profile

但此 API 与其他 Azure 管理 API 一样需要证书。我找到了以下教程 Building Real-World Cloud Apps with Windows Azure 说明如何获取证书:

$s = Get-AzureSubscription -Current
$thumbprint = $s.Certificate.Thumbprint

不幸的是,当前的 SDK $s.Certificate 总是为空,这个属性不存在。如果我手动设置证书指纹,一切都会按预期工作。

您知道如何获得正确的订阅证书吗?或者您是否有一个简单的替代方法可以将本地文件部署到 Azure 网站?

【问题讨论】:

  • 另一种方法是通过 SCM (Kudu) 站点部署文件。查看可用的 REST api (github.com/projectkudu/kudu/wiki/REST-API);具体来说,VFS 或 Zip。如果仍有问题,请告诉我们。
  • @SuwatCh 谢谢,Kudu 似乎是一个非常有趣的选择!
  • @SuwatCh 我最终使用了 kudu。这里my gist

标签: powershell azure ftp azure-web-app-service azure-powershell


【解决方案1】:

现在您似乎可以使用

访问证书指纹了
$thumbprint = $s.DefaultAccount

而不是

#$thumbprint = $s.Certificate.Thumbprint

似乎 DefaultAccount 与证书指纹的值完全相同。

这里仅供参考,这是我获取给定网站的发布配置文件的完整脚本:

Function get-AzureWebSitePublishXml
{
    Param(
        [Parameter(Mandatory = $true)]
        [String]$WebsiteName
    )

    # Get the current subscription
    $s = Get-AzureSubscription -Current
    if (!$s) {throw "Cannot get Windows Azure subscription."}

    #$thumbprint = $s.Certificate.Thumbprint #this code doesn't work anymore
    $thumbprint = $s.DefaultAccount
    if (!$thumbprint) { throw "Cannot get subscription cert thumbprint."}

    # Get the certificate of the current subscription from your local cert store
    $cert = Get-ChildItem Cert:\CurrentUser\My\$thumbprint
    if (!$cert) {throw "Cannot find subscription cert in Cert: drive."}

    $website = Get-AzureWebsite -Name $WebsiteName
    if (!$website) {throw "Cannot get Windows Azure website: $WebsiteName."}

    # Compose the REST API URI from which you will get the publish settings info
    $uri = "https://management.core.windows.net:8443/{0}/services/WebSpaces/{1}/sites/{2}/publishxml" -f `
        $s.SubscriptionId, $website.WebSpace, $Website.Name

    # Get the publish settings info from the REST API
    $publishSettings = Invoke-RestMethod -Uri $uri -Certificate $cert -Headers @{"x-ms-version" = "2013-06-01"}
    if (!$publishSettings) {throw "Cannot get Windows Azure website publishSettings."}

    return $publishSettings
}

注意:这仅在您使用 Import-AzurePublishSettingsFile 连接到 azure 时有效

谁能确认使用DefaultAccount属性是安全的?

更新

如果您使用Kudu API 上传您的网站like this,则不需要任何证书或发布配置文件。您应该使用Get-AzureWebsite 读取用户名和密码,主机名只是yourwebsitename.scm.azurewebsites.net(注意scm 段)。我建议使用 Kudu,因为它更加可靠和快速。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 2017-07-02
    • 2015-08-03
    相关资源
    最近更新 更多