답변:
여기에 PowerShell on Nano를 사용하여 zip 파일을 다운로드하는 예가 있습니다. 목적에 맞게 약간 수정해야 할 수도 있습니다.
(여기에서 https://docs.asp.net/en/latest/tutorials/nano-server.html#installing-the-asp-net-core-module-ancm )
$SourcePath = "https://dotnetcli.blob.core.windows.net/dotnet/beta/Binaries/Latest/dotnet-win-x64.latest.zip"
$DestinationPath = "C:\dotnet"
$EditionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID').EditionId
if (($EditionId -eq "ServerStandardNano") -or
($EditionId -eq "ServerDataCenterNano") -or
($EditionId -eq "NanoServer") -or
($EditionId -eq "ServerTuva")) {
$TempPath = [System.IO.Path]::GetTempFileName()
if (($SourcePath -as [System.URI]).AbsoluteURI -ne $null)
{
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.Timeout = New-Object System.TimeSpan(0, 30, 0)
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new()
$responseMsg = $client.GetAsync([System.Uri]::new($SourcePath), $cancelTokenSource.Token)
$responseMsg.Wait()
if (!$responseMsg.IsCanceled)
{
$response = $responseMsg.Result
if ($response.IsSuccessStatusCode)
{
$downloadedFileStream = [System.IO.FileStream]::new($TempPath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream)
$copyStreamOp.Wait()
$downloadedFileStream.Close()
if ($copyStreamOp.Exception -ne $null)
{
throw $copyStreamOp.Exception
}
}
}
}
else
{
throw "Cannot copy from $SourcePath"
}
[System.IO.Compression.ZipFile]::ExtractToDirectory($TempPath, $DestinationPath)
Remove-Item $TempPath
}
Invoke-WebRequest
2016 년 9 월 26 일 Windows Server 2016 누적 업데이트의 일부로 nanoserver에 추가되었습니다 .
Invoke-WebRequest ...
")
클라우드 워크로드를 지원하도록 설계된 서버 OS에는 간단한 REST / 웹 요청을위한 편리한 내장 방법이 없습니다 .O
어쨌든,이 powershell 스크립트 wget.ps1 을 사용해보십시오.이 스크립트 는 Microsoft의 스크립트 입니다. 편의를 위해 여기에 복사하여 붙여 넣기
<#
.SYNOPSIS
Downloads a file
.DESCRIPTION
Downloads a file
.PARAMETER Url
URL to file/resource to download
.PARAMETER Filename
file to save it as locally
.EXAMPLE
C:\PS> .\wget.ps1 https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
#>
Param(
[Parameter(Position=0,mandatory=$true)]
[string]$Url,
[string]$Filename = ''
)
# Get filename
if (!$Filename) {
$Filename = [System.IO.Path]::GetFileName($Url)
}
Write-Host "Download: $Url to $Filename"
# Make absolute local path
if (![System.IO.Path]::IsPathRooted($Filename)) {
$FilePath = Join-Path (Get-Item -Path ".\" -Verbose).FullName $Filename
}
if (($Url -as [System.URI]).AbsoluteURI -ne $null)
{
# Download the bits
$handler = New-Object System.Net.Http.HttpClientHandler
$client = New-Object System.Net.Http.HttpClient($handler)
$client.Timeout = New-Object System.TimeSpan(0, 30, 0)
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new()
$responseMsg = $client.GetAsync([System.Uri]::new($Url), $cancelTokenSource.Token)
$responseMsg.Wait()
if (!$responseMsg.IsCanceled)
{
$response = $responseMsg.Result
if ($response.IsSuccessStatusCode)
{
$downloadedFileStream = [System.IO.FileStream]::new($FilePath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream)
# TODO: Progress bar? Total size?
Write-Host "Downloading ..."
$copyStreamOp.Wait()
$downloadedFileStream.Close()
if ($copyStreamOp.Exception -ne $null)
{
throw $copyStreamOp.Exception
}
}
}
}
else
{
throw "Cannot download from $Url"
}