FTP SIZE request

Came across this when tried to install zip.
ContentLength is -1 when downloading from their server.
This commit is contained in:
Sergey
2017-04-15 22:41:15 +03:00
committed by GitHub
parent 480c4db441
commit 9af3e46847
+9
View File
@@ -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 };