Syncs your local directory with a remote server directory. 将本地目录与远程服务器目录同步。Allows you to optionally edit upload a file to the remote directory after it saves locally. 允许您在本地保存文件后,选择性地编辑将文件上载到远程目录。This allows you to edit more or less directly on the server similar to WinScp or other similar programs.这使您可以或多或少地直接在服务器上编辑,类似于WinScp或其他类似程序。
Very powerful, with smart features. Very simple, requires just three lines of config! Very fast, finished in a blink.动力很强,功能也很智能。非常简单,只需要三行配置!速度很快,一眨眼就完成了。
If your latest files are on the server, you can start with an empty local folder, then download your project, and from that point sync.如果你的最新文件在服务器上,你可以从一个空的本地文件夹开始,然后下载你的项目,并从那时开始同步。
VS Code
, open a local directory you wish to sync to the remote server (or create an empty directory that you wish to first download the contents of a remote server folder in order to edit locally).Ctrl+Shift+P
on Windows/Linux or Cmd+Shift+P
on Mac open command palette, run SFTP: config
command.SFTP:config
命令。sftp.json
under the .vscode
directory. sftp.json
的基本配置文件将出现在.vscode
目录下。For instance:例如:
{
"name": "Profile Name",
"host": "name_of_remote_host",
"protocol": "ftp",
"port": 21,
"secure": true,
"username": "username",
"remotePath": "/public_html/project", <---- This is the path which will be downloaded if you "Download Project"
"password": "password",
"uploadOnSave": true
}
The password parameter is optional but if you don't add it, you will be constantly prompted for a password. password参数是可选的,但如果不添加,系统会不断提示您输入密码。Note that you must escape any backslashes and other special characters with a backslash.请注意,必须用反斜杠转义任何反斜杠和其他特殊字符。
There are other Example Configs below.下面还有其他示例配置。
sftp.json
file.sftp.json
文件。Ctrl+Shift+P
on Windows/Linux or Cmd+Shift+P
on Mac open command palette.SFTP: Download Project
. SFTP: Download Project
。remotePath
setting in sftp.json
to your local open directory.sftp.json
中remotePath
设置中显示的目录下载到您的本地打开目录。For detailed usage. 详细用法。Please go to wiki.请访问wiki。
You can see the full config here.你可以在这里看到完整的配置。
{
"host": "host",
"username": "username",
"remotePath": "/remote/workspace"
}
{
"username": "username",
"password": "password",
"remotePath": "/remote/workspace/a",
"watcher": {
"files": "dist/*.{js,css}",
"autoUpload": false,
"autoDelete": false
},
"profiles": {
"dev": {
"host": "dev-host",
"remotePath": "/dev",
"uploadOnSave": true
},
"prod": {
"host": "prod-host",
"remotePath": "/prod"
}
},
"defaultProfile": "dev"
}
Note: context
and 和watcher
are only available at root level.仅在根级别可用。
Use 使用SFTP: Set Profile
to switch profile.SFTP: Set Profile
以切换配置文件。
The context must not be same.上下文不能相同。
[
{
"name": "server1",
"context": "project/build",
"host": "host",
"username": "username",
"password": "password",
"remotePath": "/remote/project/build"
},
{
"name": "server2",
"context": "project/src",
"host": "host",
"username": "username",
"password": "password",
"remotePath": "/remote/project/src"
}
]
Note: 此模式下需要name
is required in this mode.name
。
You can connect to a target server through a proxy with ssh protocol.您可以通过使用ssh协议的代理连接到目标服务器。
Note: Variable substitution is not working in a hop config.变量替换在跃点配置中不起作用。
local -> hop -> target
{
"name": "target",
"remotePath": "/path/in/target",
// hop
"host": "hopHost",
"username": "hopUsername",
"privateKeyPath": "/Users/localUser/.ssh/id_rsa", // The key file is assumed on the local.
"hop": {
// target
"host": "targetHost",
"username": "targetUsername",
"privateKeyPath": "/Users/hopUser/.ssh/id_rsa", // The key file is assumed on the hop.
}
}
local -> hopa -> hopb -> target
{
"name": "target",
"remotePath": "/path/in/target",
// hopa
"host": "hopAHost",
"username": "hopAUsername",
"privateKeyPath": "/Users/hopAUsername/.ssh/id_rsa" // The key file is assumed on the local.
"hop": [
// hopb
{
"host": "hopBHost",
"username": "hopBUsername",
"privateKeyPath": "/Users/hopaUser/.ssh/id_rsa" // The key file is assumed on the hopa.
},
// target
{
"host": "targetHost",
"username": "targetUsername",
"privateKeyPath": "/Users/hopbUser/.ssh/id_rsa", // The key file is assumed on the hopb.
}
]
}
You can use 您可以使用remote
to tell sftp to get the config from remote-fs.remote
告诉sftp从远程fs获取配置。
In User Setting:在用户设置中:
"remotefs.remote": {
"dev": {
"scheme": "sftp",
"host": "host",
"username": "username",
"rootPath": "/path/to/somewhere"
},
"projectX": {
"scheme": "sftp",
"host": "host",
"username": "username",
"privateKeyPath": "/Users/xx/.ssh/id_rsa",
"rootPath": "/home/foo/some/projectx"
}
}
In sftp.json:在sftp.json
中:
{
"remote": "dev",
"remotePath": "/home/xx/",
"uploadOnSave": true,
"ignore": [".vscode", ".git", ".DS_Store"]
}
Remote Explorer lets you explore files in remote. 远程资源管理器允许您以远程方式浏览文件。You can open Remote Explorer by:您可以通过以下方式打开远程资源管理器:
View: Show SFTP
.View: Show SFTP
。You can only view a files content with Remote Explorer. 您只能使用远程资源管理器查看文件内容。Run command 运行命令SFTP: Edit in Local
to edit it in local.SFTP: Edit in Local
以在本地编辑它。
Note: You need to manually refresh the parent folder after you delete a file to make the explorer updated.删除文件后,您需要手动刷新父文件夹以更新资源管理器。
Open User Settings.打开“用户设置”。
File > Preferences > Settings
Code > Preferences > Settings
Set sftp.debug
to true
and reload vscode.
View the logs in View > Output > sftp
.