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}:stable 或 insider
    • {os}-{arch}:win32-x64、linux-x64、linux-arm64 等
  • 安装目录:%USERPROFILE%\.vscode-server-insiders\bin\{commit}\(Insiders)或 %USERPROFILE%\.vscode-server\bin\{commit}\(Stable)
  • VS Code Remote SSH 扩展中,remote.SSH.useOSS 和 remote.SSH.ossDownloadUrl 可以覆盖 Linux 远程的下载源,但 Windows 远程的 PowerShell 下载脚本硬编码了 update.code.visualstudio.com,无法通过设置修改
相关推荐
2601_9623649714 小时前
企业 PC 安全升级,Windows Hello 商用生物识别模组介绍
windows·安全
snysy16 小时前
服务器安全加固与入侵检测实战:从SSH加固、防火墙策略到挖矿木马排查
服务器·安全·ssh
2501_9160074716 小时前
Windows OpenSSL 生成 iOS 证书,制作 p12 与描述文件,KXBuild 签名实操
windows·vscode·ios·objective-c·个人开发·swift·敏捷流程
Linux_cy18 小时前
nginx 502 排查手册:九种原因分类、定位命令与检查顺序
linux·运维·服务器·网络·数据库·nginx·ssh
椒颜皮皮虾྅18 小时前
模型部署不再卡在环境上:DeploySharp 四大推理引擎与 Windows/Linux 离线交付实战
linux·运维·开发语言·人工智能·windows·计算机视觉·cuda
昂好的day18 小时前
C# 同步异步与多线程:Thread / Task / 线程池一次讲透(上篇)
开发语言·windows·c#
垆边人似月.18 小时前
Ubuntu 配置 Samba 共享文件夹并映射到 Windows 完整指南
linux·windows·ubuntu
瓶 盖19 小时前
你的 IDE 插件改了 authorized_keys:Claude Code 扩展投毒链路拆解
ide·ssh·vs code·安全分析·供应链安全·claude code
BIBI20491 天前
换 Git 托管平台怎么做?基于 TortoiseGit 的跨平台迁移教程
windows·git·tortoisegit·问题解决·版本控制·最佳实践
chushiyunen1 天前
autoHotKey、windows自动化快捷键工具
运维·windows·自动化