& { $Base = 'https://ftp.five.rest/_/' function Get-Listing([string]$Url) { $data = Invoke-RestMethod -Uri $Url -Headers @{ Accept = 'application/json' } if ($null -eq $data) { return @() } if ($data -is [string]) { throw "Сервер вернул не список файлов" } return @($data) } function Format-Size([long]$Size) { if ($Size -ge 1GB) { return ('{0:N1} ГБ' -f ($Size / 1GB)) } if ($Size -ge 1MB) { return ('{0:N1} МБ' -f ($Size / 1MB)) } if ($Size -ge 1KB) { return ('{0:N1} КБ' -f ($Size / 1KB)) } return "$Size Б" } $url = $Base while ($true) { $shown = [Uri]::UnescapeDataString(([Uri]$url).AbsolutePath) if ($shown.StartsWith('/_/')) { $shown = $shown.Substring(2) } if (-not $shown.EndsWith('/')) { $shown += '/' } Write-Host "" Write-Host $shown try { $items = @(Get-Listing $url) } catch { Write-Host $_.Exception.Message break } if ($items.Count -eq 0) { Write-Host '(пусто)' } for ($i = 0; $i -lt $items.Count; $i++) { $it = $items[$i] if ($it.is_dir) { '{0,3} {1}' -f ($i + 1), $it.name | Write-Host } else { '{0,3} {1} ({2})' -f ($i + 1), $it.name, (Format-Size ([long]$it.size)) | Write-Host } } Write-Host ' 0 ..' Write-Host ' q выход' $choice = (Read-Host 'Номер').Trim() if ($choice -eq 'q') { break } if ($choice -eq '0') { $path = ([Uri]$url).AbsolutePath.TrimEnd('/') if ($path -eq '/_') { continue } $abs = ([Uri]$url).AbsoluteUri.TrimEnd('/') $url = $abs.Substring(0, $abs.LastIndexOf('/') + 1) continue } $n = 0 if (-not [int]::TryParse($choice, [ref]$n) -or $n -lt 1 -or $n -gt $items.Count) { Write-Host 'Нет такого пункта' continue } $item = $items[$n - 1] $next = ([Uri]::new([Uri]$url, [string]$item.url)).AbsoluteUri if ($item.is_dir) { if (-not $next.EndsWith('/')) { $next += '/' } $url = $next continue } $dest = Join-Path (Get-Location) ([string]$item.name) $save = (Read-Host "Куда сохранить [$dest]").Trim() if (-not $save) { $save = $dest } $dir = Split-Path -Parent $save if ($dir -and -not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Path $dir | Out-Null } Invoke-WebRequest -Uri $next -OutFile $save -UseBasicParsing Write-Host "Скачано: $save" } }