VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传

环境

项目
本地系统 Windows 11
远程系统 Windows Server 2025 Datacenter (Build 26100)
VS Code Insiders 1.110.0 (404102fc70f6f15e1aba226b6d56f4c75bd5fa4e)
Remote SSH 扩展 ms-vscode-remote.remote-ssh 0.122.0
连接方式 OpenSSH,公钥认证

现象

VS Code Remote SSH 连接远程 Windows 服务器时,永久卡在"正在下载 VS Code 服务器" ,进度不动,最终超时失败。SSH 连接本身正常(ssh 上科大A服务器 "echo connected" 能输出 connected)。

诊断过程

1. 定位 DNS 解析问题

VS Code Server 下载流程:update.code.visualstudio.com → 302 重定向 → vscode.download.prcdn.microsoft.com

在远程服务器上用 nslookup 测试:

cmd 复制代码
nslookup vscode.download.prcdn.microsoft.com
arduino 复制代码
*** UnKnown can't find vscode.download.prcdn.microsoft.com: Non-existent domain

根因找到:远程服务器的内网 DNS(192.168.1.5)无法解析 prcdn.microsoft.com 域名。

2. 排查可用的 CDN

微软 VS Code 有多个 CDN 域名。逐一在远程服务器上测试 DNS 解析:

CDN 域名 DNS 解析 说明
vscode.download.prcdn.microsoft.com 失败 默认重定向目标
az764295.vo.msecnd.net 成功 旧版 CDN,本地也无法解析
vscode.download.prss.microsoft.com 成功 解析到金山云 CDN 节点

在远程服务器上验证 prss 域名可达:

powershell 复制代码
# 在远程服务器上执行
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(Invoke-WebRequest -Uri 'https://vscode.download.prss.microsoft.com/dbazure/download/insider/<commit>/vscode-server-win32-x64.zip' -Method Head -UseBasicParsing -TimeoutSec 10).StatusCode
# 返回 200

3. 发现连接不稳定问题

虽然 prss CDN 可达,但直接用 WebClient.DownloadFile() 下载时,约在传输 25MB(~39%)时连接中断,zip 文件不完整,无法解压。多次尝试均在相同位置断开,说明是 CDN 边缘节点的连接保持问题。

4. 排除镜像方案

批量测试了 10+ 个国内镜像(华为云、阿里云、腾讯云、npmmirror、中科大、山大等),Insiders 版本均未被同步,全部 404 或返回 HTML 错误页。镜像方案仅适用于 Stable 版。

解决方案:BITS 断点续传

Windows 自带的 BITS(后台智能传输服务)原生支持断点续传,连接中断后自动恢复。将以下脚本保存到远程服务器并执行:

powershell 复制代码
# install-vscode-server.ps1
# 用法:修改 $commit 为你的 VS Code commit ID,然后在远程服务器上执行

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$commit = "404102fc70f6f15e1aba226b6d56f4c75bd5fa4e"  # ← 替换为你的 commit ID
$url = "https://vscode.download.prss.microsoft.com/dbazure/download/insider/$commit/vscode-server-win32-x64.zip"
# Stable 版本把 insider 改为 stable

$dir = "$env:USERPROFILE\.vscode-server-insiders\bin\$commit"
# Stable 版本用 .vscode-server 而非 .vscode-server-insiders
$zip = "$dir\vscode-server.zip"

New-Item -ItemType Directory -Force $dir | Out-Null
Remove-Item $zip -Force -ErrorAction SilentlyContinue

# BITS 下载,自动断点续传
Write-Host "Downloading via BITS..."
$job = Start-BitsTransfer -Source $url -Destination $zip -Asynchronous
$retries = 0
while ($job.JobState -ne 'Transferred' -and $retries -lt 3) {
    if ($job.JobState -eq 'TransientError' -or $job.JobState -eq 'Error') {
        Write-Host "Transfer interrupted, resuming... (attempt $($retries+1))"
        Resume-BitsTransfer -BitsJob $job -Asynchronous
        $retries++
    }
    $pct = if ($job.BytesTotal -gt 0) { [math]::Round($job.BytesTransferred/$job.BytesTotal*100,1) } else { 0 }
    Write-Host "  $pct% ($($job.BytesTransferred) / $($job.BytesTotal))"
    Start-Sleep -Seconds 3
}
if ($job.JobState -eq 'Transferred') {
    Complete-BitsTransfer -BitsJob $job
    Write-Host "Download complete!"
} else {
    Write-Host "BITS failed: $($job.JobState)"; exit 1
}

# 解压
Write-Host "Extracting..."
Expand-Archive -Path $zip -DestinationPath $dir -Force
Remove-Item $zip -Force

# 如果解压后多了一层目录,提升到上层
$sub = Get-ChildItem $dir -Directory | Select-Object -First 1
if ($sub) {
    Get-ChildItem $sub.FullName | Move-Item -Destination $dir -Force
    Remove-Item $sub.FullName -Recurse -Force
}

Write-Host "Installed! Verify:"
Get-ChildItem $dir | Select-Object Name

获取 Commit ID

在本地 VS Code 中按 Ctrl+Shift+P → 输入 About → 找到"提交"后面的 40 位哈希值。 或者用命令行:

powershell 复制代码
code-insiders --version   # 第二行就是 commit ID
# 或者 code --version(Stable 版)

执行方式

可以通过 SSH 从本地推送并执行:

powershell 复制代码
scp install-vscode-server.ps1 "远程主机:D:/Users/用户名/install-vscode-server.ps1"
ssh 远程主机 "powershell -ExecutionPolicy Bypass -File D:\Users\用户名\install-vscode-server.ps1"

实际效果

erlang 复制代码
Downloading via BITS...
  78.3% (50069504 / 63943408) - Transferring
  91.9% (58760060 / 63943408) - Transferring   ← 在此断连
Transfer interrupted, resuming... (attempt 1)  ← BITS 自动续传
  92% (58825596 / 63943408) - Connecting
  98.2% (62763418 / 63943408) - Transferring   ← 续传再次断连后再次恢复
Download complete!
Downloaded 63943408 bytes                       ← 完整文件
Extracting...
Installed!

安装完成后重启 VS Code 重新连接,不再卡在下载阶段。

现有方案对比

网上大量文章都是针对 Linux 远程服务器,方案为"手动 wget 下载 + scp 传输 + tar 解压"。本文场景的区别:

差异点 网上常见方案 本文场景
远程 OS Linux Windows Server
失败原因 服务器无外网 有外网但 prcdn DNS 无法解析
下载格式 .tar.gz .zip
传输问题 CDN 连接 ~25MB 后中断
解决手段 scp + tar BITS 断点续传
适用版本 Stable Stable + Insiders(镜像站不同步 Insiders)

关键信息速查

  • VS Code Server 下载 URL 模板:https://vscode.download.prss.microsoft.com/dbazure/download/{quality}/{commit}/vscode-server-{os}-{arch}.zip
    • {quality}stableinsider
    • {os}-{arch}win32-x64linux-x64linux-arm64
  • 安装目录:%USERPROFILE%\.vscode-server-insiders\bin\{commit}\(Insiders)或 %USERPROFILE%\.vscode-server\bin\{commit}\(Stable)
  • VS Code Remote SSH 扩展中,remote.SSH.useOSSremote.SSH.ossDownloadUrl 可以覆盖 Linux 远程的下载源,但 Windows 远程的 PowerShell 下载脚本硬编码了 update.code.visualstudio.com,无法通过设置修改
相关推荐
jyOverQ12 小时前
ChatGPT Windows 客户端点击无反应、有进程却没窗口?一次 MSIX 非系统盘启动卡死的完整排查
windows·chatgpt
还是大剑师兰特15 小时前
MySQL8.0 Windows完整安装教程
windows·mysql·大剑师
redfred17 小时前
HandBrake 使用教程:开源视频压缩工具 视频太大压缩 MKV转MP4 批量转码 硬件加速 Windows/macOS/Linux
windows·开源·音视频
kakakahahahaha17 小时前
【Windows】C盘拒绝访问0x80070005的7步排查
windows·电脑·内容运营·软件需求
万年咸鱼19 小时前
Java ArrayList 详解:原理、用法与实战
java·开发语言·windows
奈斯先生Vector20 小时前
本地图片识别怎么接入多模态 AI?用 Python API 理解 GPT-4o Vision 的真实工作流
开发语言·人工智能·windows·python·网络协议·http·aigc
yyywxk20 小时前
ChatGPT/Codex Windows 桌面版“幽灵会话”问题:网页端已删除,桌面端仍显示且无法删除/归档
windows·chatgpt
万年咸鱼21 小时前
Java List 接口详解:从基础到实战
java·windows·list
Neighbor_OldY21 小时前
【实战复盘】RDP暴力破解与内网横向移动溯源:Windows全套排查命令与事件ID硬核解析
运维·windows·web安全
深念Y1 天前
Windows 11 工具链部署与 SSH 踩坑笔记
windows·笔记·ssh