在Windows命令提示符/ PowerShell中下载大文件
发布时间:2020-12-14 05:34:25 所属栏目:Windows 来源:网络整理
导读:我现在已经没有选择…… 尝试1 在Powershell中使用iwr.它工作,显示进度,但它的速度慢10倍,并且直到文件在内存中时才会刷新:(. powershell -command " { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile
我现在已经没有选择……
尝试1 在Powershell中使用iwr.它工作,显示进度,但它的速度慢10倍,并且直到文件在内存中时才会刷新:(. powershell -command "& { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile SUV.zip }" 尝试2 在Powershell中使用.Net 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禁止错误)! 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,$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,$count) $count = $responseStream.Read($buffer,$buffer.length) $downloadedBytes = $downloadedBytes + $count } "Finished Download" $targetStream.Flush() $targetStream.Close() $targetStream.Dispose() $responseStream.Dispose() } downloadFile "http://URL_to_your_file" "C:Pathtodestination.file" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读