0

나는 가지 PowerShell에서다운로드 큰 파일/명령 프롬프트 PowerShell을

시도를 ... 이제 선택의 여지 1

사용 IWR를 실행하고 있습니다. 그것은 진행 표시하지만, 작품의 10 배 느린 파일 :(메모리에있는 동안까지 플러시하지 않습니다.

powershell -command "& { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile SUV.zip }" 

시도 2 ​​

사용 닷넷 PowerShell에서 WebClient를. 그것은 작동하지만 표시 당신은 Ctrl + C :(으로 종료 할 수없고 진행. 마지막 문제는 큰 좌절이다.

powershell -command "& { (New-Object System.Net.WebClient).DownloadFile('https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip', 'SUV.zip') }" 

시도 3

Powershell에서 BITS 전송을 사용하십시오. 그것은 작동하고, 진도를 보여주고 거의 완벽한 ... 당신이 그것을 발견 할 때까지 mysteriously doesn't work on GitHub (금지 된 403을 가진 과실) !!

+0

왜 실행'powershell.exe' 별도로 ('에는 powershell.exe - 명령 ...')? PowerShell 명령 줄에서 직접 필요한 명령을 실행하기 만하면됩니다. –

+0

다른 빌드 스크립트에서이 스크립트를 사용하고 있습니다. 전체 스크립트를 PS로 변환하는 것은 현재로서는 목표가 아닙니다. – ShitalShah

답변

0

원래이 코드를 어디에서 얻었는지 확실하지 않지만 여러 번 수정했습니다. 희망이 당신을 도울 것입니다.

function downloadFile($url, $targetFile) 
{ 
    "Downloading $url" 
    $uri = New-Object "System.Uri" "$url" 
    $request = [System.Net.HttpWebRequest]::Create($uri) 
    $request.set_Timeout(15000) #15 second timeout 
    $response = $request.GetResponse() 
    $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024) 
    $responseStream = $response.GetResponseStream() 
    $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create 
    $buffer = new-object byte[] 10KB 
    $count = $responseStream.Read($buffer,0,$buffer.length) 
    $downloadedBytes = $count 
    while ($count -gt 0) 
    { 
     [System.Console]::CursorLeft = 0 
     [System.Console]::Write("Downloaded {0}K of {1}K", [System.Math]::Floor($downloadedBytes/1024), $totalLength) 
     $targetStream.Write($buffer, 0, $count) 
     $count = $responseStream.Read($buffer,0,$buffer.length) 
     $downloadedBytes = $downloadedBytes + $count 
    } 
    "Finished Download" 
    $targetStream.Flush() 
    $targetStream.Close() 
    $targetStream.Dispose() 
    $responseStream.Dispose() 
} 

downloadFile "http://URL_to_your_file" "C:\Path\to\destination.file" 
+0

사용자가 Ctrl + C로 취소 할 수 있습니까? – ShitalShah

0

는 여기에 내가 @MDMarra의 호의를 발견 PowerShell을 2.0 웹에서 파일을 다운로드 주장 코드 블록 (내게로) 안된입니다. 현재 업무에서 주석이 무엇을 말하는지 실제로 볼 수는 없습니다.

$webClient = New-Object System.Net.WebClient $webURL = "http://www.google.com/index.html" $filePath = "c:\whatever\index.html" $webclient.DownloadFile($webURL,$filePath)

+0

이것은 정확하게 내 질문에 설명 된 접근 방식 # 2입니다. 그것은 내 질문에 대답하지 않습니다. – ShitalShah