From 9af3e468477a8dc7d36a605bcbfaabdd366a8d9b Mon Sep 17 00:00:00 2001 From: Sergey Date: Sat, 15 Apr 2017 22:41:15 +0300 Subject: [PATCH] FTP SIZE request Came across this when tried to install zip. ContentLength is -1 when downloading from their server. --- lib/install.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/install.ps1 b/lib/install.ps1 index 97a674eef..1fe249af9 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -170,6 +170,9 @@ function dl($url, $to, $cookies, $progress) { $wres = $wreq.getresponse() $total = $wres.ContentLength + if($total -eq -1 -and $wreq -is [net.ftpwebrequest]) { + $total = ftp_file_size($url) + } if ($progress -and ($total -gt 0)) { [console]::CursorVisible = $false @@ -424,6 +427,12 @@ function is_in_dir($dir, $check) { $check -match "^$([regex]::escape("$dir"))(\\|`$)" } +function ftp_file_size($url) { + $request = [net.ftpwebrequest]::create($url) + $request.method = [net.webrequestmethods+ftp]::getfilesize + $request.getresponse().contentlength +} + # hashes function hash_for_url($manifest, $url, $arch) { $hashes = @(hash $manifest $arch) | ? { $_ -ne $null };