You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中ftp-simple连接报错:Cannot read properties of undefined (reading '0')

解决VS Code ftp-simple插件「Cannot read properties of undefined (reading '0')」错误及WordPress文件实时编辑方案

问题详情

我在全新安装的VS Code中创建了Projects文件夹及其中的Website App项目,在项目的.vscode目录下创建了ftp-simple.json配置文件,内容如下:

{    
    "remote-workspace": [    
        {        
            "name": "Website App",        
            "host": "giowm1136.siteground.biz",        
            "port": 21,        
            "type": "ftp",        
            "username": "ftp@mysite.com",        
            "password": "***",        
            "path": "/public_html/wp-content/themes/astra-child",        
            "autosave": true,        
            "encoding": "utf8",        
            "protocol": "ftp",        
            "passive": true       
        }    
    ]
}

这些登录凭据在FileZilla中可正常连接,但执行ftp-simple: FTP Config Settings命令时弹出错误:Command 'ftp-simple: Config - FTP connection setting' resulting in an error. Cannot read properties of undefined (reading '0'),输出窗口显示远程工作区路径为c:/Users/***/AppData/Roaming/Code/User/globalStorage/humy2833.ftp-simple/remote-workspace-temp。由于ftp-simple多年未更新无官方支持,需要找到能在VS Code中实时编辑WordPress文件(如functions.php)的解决办法。

解决方案

一、修复ftp-simple插件的配置问题

  1. 确认配置文件位置
    ftp-simple的全局配置文件默认存储在%APPDATA%\Code\User\globalStorage\humy2833.ftp-simple\ftp-simple.json,而非项目.vscode目录下。你当前在项目目录下的配置可能未被插件读取,导致无法识别remote-workspace数组,触发读取索引0的错误。

  2. 迁移并校验配置格式

  • 把项目.vscode下的ftp-simple.json内容复制到全局配置文件中
  • 检查JSON格式:确保逗号、括号无遗漏,可移除冗余字段(比如配置中type和protocol均为ftp,保留一个即可),修改后的配置示例:
{    
    "remote-workspace": [    
        {        
            "name": "Website App",        
            "host": "giowm1136.siteground.biz",        
            "port": 21,        
            "type": "ftp",        
            "username": "ftp@mysite.com",        
            "password": "***",        
            "path": "/public_html/wp-content/themes/astra-child",        
            "autosave": true,        
            "encoding": "utf8",        
            "passive": true       
        }    
    ]
}
  1. 重置插件缓存
  • 关闭VS Code,删除c:/Users/***/AppData/Roaming/Code/User/globalStorage/humy2833.ftp-simple/remote-workspace-temp目录
  • 重新打开VS Code,执行ftp-simple: Connect to FTP/SFTP命令尝试连接

二、替代方案(推荐,因ftp-simple已停止维护)

由于ftp-simple多年未更新,兼容性问题会持续出现,推荐使用以下活跃维护的插件实现实时编辑:

  • SFTP Sync:支持FTP/SFTP,配置方式类似ftp-simple,支持自动同步、远程浏览,更新频繁
  • Remote - FTP:VS Code生态中稳定的远程FTP插件,支持实时编辑和自动保存
  • WordPress Development Kit:针对WordPress开发的专用插件,除文件同步外,还集成代码提示、调试等功能

以Remote - FTP为例,配置步骤:

  1. 安装插件后,在项目.vscode目录下创建settings.json,添加配置:
{
    "remote.ftp.host": "giowm1136.siteground.biz",
    "remote.ftp.port": 21,
    "remote.ftp.username": "ftp@mysite.com",
    "remote.ftp.password": "***",
    "remote.ftp.root": "/public_html/wp-content/themes/astra-child",
    "remote.ftp.autosave": true
}
  1. 打开命令面板执行Remote FTP: Connect,即可连接到远程WordPress主题目录,实时编辑functions.php等文件

内容的提问来源于stack exchange,提问作者xar86413

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 10:43:29