下载Windows中大型文件的命令提示符/ PowerShell的
我在PowerShell中那种跑出来的选项现在......下载Windows中大型文件的命令提示符/ PowerShell的
尝试1
使用IWR。它的工作原理,显示了进步,但它的10X速度较慢,不冲水,直到当文件在内存中:(。
powershell -command "& { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile SUV.zip }"
尝试2
使用的.Net Web客户端在PowerShell中,它的工作原理,但目前尚无你不能按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禁止)!
powershell -command "& { Start-BitsTransfer -Source https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -Destination SUV.zip }"
不知道我从哪里得到这段代码,但我已经修改了几次。希望这会帮助你。
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"
用户可以通过Ctrl + C取消这个功能吗? – ShitalShah
下面是一个未经测试(由我)的代码块,声称在PowerShell 2.0中的网站,我发现@MDMarra礼貌下载文件。在目前的工作中,无法看出它是否真的按照锡上的说法行事。
$webClient = New-Object System.Net.WebClient $webURL = "http://www.google.com/index.html" $filePath = "c:\whatever\index.html" $webclient.DownloadFile($webURL,$filePath)
这正是我的问题中描述的方法#2。它不回答我的问题。 – ShitalShah
为什么单独运行'powershell.exe'('powershell.exe -command ...')?只需从PowerShell命令行直接运行所需的命令即可。 –
我从另一个构建脚本中使用它,并将整个脚本转换为PS并不是我们现在的目标。 – ShitalShah