Skip to content

About the author of Daydream Drift

Tomasz Niezgoda (LinkedIn/tomaszniezgoda & GitHub/tniezg) is the author of this blog. It contains original content written with care.

Please link back to this website when referencing any of the materials.

Author:

Share VSCode SFTP Options

Published

This tip relates to the awesome vscode-sftp extension for Visual Studio Code. I've used it for months and believe it's the best for syncing local files to a remote server and back. No configuration is required on the remote except support for SFTP.

vscode-sftp can work with an unlimited number of remote directories. However, copying the same configuration every time a new remote directory is synced is a hassle. Fortunately, there's a way to share most of it, by placing defaults in the generic VSCode Settings.

In VSCode, click menu -> Code [Insiders] -> Preferences -> Settings and add the following (or similar) configuration:

"remotefs.remote": {
		"dev": {
			"protocol": "sftp",
			"host": "dev",
			"username": "root",
			"privateKeyPath": "~/<PATH_TO_PRIVATE_KEY_FILE>",
			"password": null,
			"agent": null,
			"uploadOnSave": false,
			"passphrase": null,
			"passive": false,
			"interactiveAuth": false,
			"port": 22,
			"syncMode": "full",
			"watcher": {
				"files": "**/*",
				"autoUpload": true,
				"autoDelete": true
			},
			"ignore": [
				"**/.vscode/**",
				"**/.git/**",
				"**/.DS_Store",
				"**/node_modules/**"
			]
		}
	}
}

While VSCode will warn about an "Unknown configuration setting" after placing the remotefs.remote key in the config, it will be used by the extension anyway.

To use something other than a specific IP adress in the host key, like "dev" above, put a new mapping in the operating system's /etc/hosts file (macOS). In the example below, I added <IP_ADDRESS_HERE> dev

Then, in any local directory meant for syncing, inside of /.vscode/sftp.json, place:

{
  "remote": "dev",
  "remotePath": "<ABSOLUTE_REMOTE_DIRECTORY_PATH>"
}

These two lines are enough to setup a remote project locally.

Last step: open Command Palette (macOS: shift+cmd+P), type "reload" and reload the window. Otherwise the extension won't recognize the directory has an SFTP configuration.

Screenshot-2019-01-19-at-16.29.47