使用 FTP 将文件发布到 Azure Web 应用时出错



我正在按照此 MSDN 指南将 ASP.Net Web 应用程序文件发布/上传到 Azure Web 应用程序(资源管理器(。但是每当子文件夹启动时都会收到上传文件错误。根文件夹运行正常。


上传到 ftp://XXXXXX.ftp.azurewebsites.windows.net/site/wwwroot/bin/Antlr3.Runtime.dll From C:\Users\SampleWebApp\bin\Antlr3.Runtime.dll

使用"2"参数调用"上传文件"的异常:

远程服务器返回错误:(550( 文件不可用(例如,找不到文件,无法访问(


Param(
[string] [Parameter(Mandatory=$true)] $AppDirectory, 
[string] [Parameter(Mandatory=$true)] $WebAppName, 
[string] [Parameter(Mandatory=$true)] $ResourceGroupName 
)
$xml = [Xml](Get-AzureRmWebAppPublishingProfile -Name $webappname `
-ResourceGroupName $ResourceGroupName `
-OutputFile null)
$username = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userName").value
$password = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userPWD").value
$url = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@publishUrl").value
Set-Location $appdirectory
$webclient = New-Object -TypeName System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($username,$password)
$files = Get-ChildItem -Path $appdirectory -Recurse | Where-Object{!($_.PSIsContainer)}
foreach ($file in $files)
{
if ($file.FullName)
$relativepath = (Resolve-Path -Path $file.FullName -Relative).Replace(".", "").Replace('', '/')
$uri = New-Object System.Uri("$url/$relativepath")
"Uploading to " + $uri.AbsoluteUri
"From " + $file.FullName
$webclient.UploadFile($uri, $file.FullName)
} 
$webclient.Dispose()

由于问题仅在第一次出现子目录(bin(文件时开始,这可能是因为其他一些进程正在使用Antlr dll。 是否可以关闭所有活动的调试会话并再次运行此脚本? 并确保在形成相对 URI 路径后没有任何空格

[更新]无法创建子目录,因此从子目录上传文件时出现错误"找不到文件"。

在从子目录上传文件之前,在for循环中进行了一些更改以在ftp上创建子目录,并且工作正常。

$appdirectory="<Replace with your app directory>"
$webappname="mywebapp$(Get-Random)"
$location="West Europe"
# Create a resource group.
New-AzureRmResourceGroup -Name myResourceGroup -Location $location
# Create an App Service plan in `Free` tier.
New-AzureRmAppServicePlan -Name $webappname -Location $location `
-ResourceGroupName myResourceGroup -Tier Free
# Create a web app.
New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname `
-ResourceGroupName myResourceGroup
# Get publishing profile for the web app
$xml = (Get-AzureRmWebAppPublishingProfile -Name $webappname `
-ResourceGroupName myResourceGroup `
-OutputFile null)
# Not in Original Script
$xml = [xml]$xml
# Extract connection information from publishing profile
$username = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userName").value
$password = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userPWD").value
$url = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@publishUrl").value
# Upload files recursively 
Set-Location $appdirectory
$webclient = New-Object -TypeName System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($username,$password)
$files = Get-ChildItem -Path $appdirectory -Recurse #Removed IsContainer condition
foreach ($file in $files)
{
$relativepath = (Resolve-Path -Path $file.FullName -Relative).Replace(".", "").Replace('', '/')  
$uri = New-Object System.Uri("$url/$relativepath")
if($file.PSIsContainer)
{
$uri.AbsolutePath + "is Directory"
$ftprequest = [System.Net.FtpWebRequest]::Create($uri);
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::MakeDirectory
$ftprequest.UseBinary = $true
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password)
$response = $ftprequest.GetResponse();
$response.StatusDescription
continue
}
"Uploading to " + $uri.AbsoluteUri + " from "+ $file.FullName
$webclient.UploadFile($uri, $file.FullName)
} 
$webclient.Dispose()

我还在博客上详细介绍了如何解决此问题以在此处获得修复。

最新更新