This article is the second in a series about sublime text and how to set it up for remote development using the SFTP package. I suggest you refer to our previous article about the installation and configuration of sublime text 3.
Most of our development and deployment work will be happening in the remote server or cloud servers. In that case, we can use the sublime SFTP package to work with remote servers where we can push (Local to remote) or pull (Remote to Local) the codes/files using file transfer protocol. SFTP comes with a license cost but we can install the package and use it for an indefinite time.
Features of Sublime Text sFTP
- FTP, SFTP, and FTPS protocols are supported.
- Can either use password or SSH key-based authentication.
- Sync folders – Locally, Remotely, and Bi-directionally.
- Possible to sync only recently made changes.
- The difference in local vs. remote versions of a file.
- Persistent connections for good performance.
Installing sFTP on Sublime Text Editor
Assuming that you have installed and configured package control as described in the article, COMMAND PALLET [ CTRL + SHIFT + P ] → INSTALL PACKAGE → SFTP.
Now open COMMAND PALLET
[ CTRL + SHIFT + P ] → Type SFTP. You will find several options to work with SFTP functionalities. We will explore all of these options over the course of this article.
I have a directory where it contains two python scripts which will be Synced to a remote machine. My remote machine is Linux Mint 19.3 running on a VM. Now let’s configure the remote setup. Right-click on the project folder → SFTP/FTP → Map to Remote.
sftp-config.json file will be created in the project folder which holds the remote configuration settings.
Let’s break down the settings and configure some important parameters. There are three different protocols (SFTP, FTP, and FTPS) can be used. Here we will use “SFTP”.
We will now configure remote host information like hostname, username, and port. Password will be prompted when we start the sync. The hostname can be FQDN or IP address and by default port number is 22.
SSH key-based authentication is also possible, we can create a Public-Private key pair and the key can be pointed to the location using the parameter “ssh_Key_file”.
Configure the remote directory path “remote_path” where the project files and folders need to be synced. We can also set file and directory permission using “file_permission” and “dir_permission” parameters. We can ignore files and folders to be synced by providing the file identifier in “ignore_regexes”.
We have done some mandatory configuration in
sftp-config.json to start syncing our files to the remote machine. We have a few more options to configure depending upon the need. But as of now, these are the important parameters that we need to get going. Now in my remote machine, my directory
/home/tecmint is empty. We will upload the project folder to
Right-click on project folder → SFTP/FTP.
Sublime Text sFTP Operations and Usage
Let’s break down all the options.
Will upload the local project folder to the remote directory configured in the
sftp-config.json file. All the operations will be displayed at the bottom of the Sublime Text.
Both the files in the local directory are uploaded to the remote directory. The
sftp-config.json files will be skipped.
Rename Local and Remote Folders
We can rename both remote and local directory at the same time by choosing rename local and remote folders options. It will prompt you to enter a new name at the bottom of ST.
Delete Local and Remote Folder
This option will delete the current project folder from both remote machine and local machine along with
Local → Remote
Upload the files/folders to the remote machine. Difference between upload and sync is, sync will delete any extra files that are not in the local project folder. To demonstrate this I had created a file called “dummy.py” in my remote machine.
Now I try to sync the local → remote, it will prompt me with confirmation and the file dummy.py will be removed automatically.
Remote → Local
Sync remote files locally and remove any extra files in the local project folder.
Sync both directions will allow us to keep identical copies in both remote and local. It will be useful when we are making different changes to local as well as remote folders at the same time.
We can access the remote files and folders other than the project directory using the browse remote option.
Multiple Remote Mapping
Now we have configured one remote host for syncing our project. It is also possible to create multiple remote mappings. Choose the “Alternate Remote Mapping” option which will create sftp-config-alt.json.
This is the same configuration file as the sftp-config.json file where we have to configure a second remote host. I have configured the second remote information and saved it. We can have multiple remote mapping configured.
We can now decide which remote mapping to choose from.
Select “Switch Remote Mapping…” option. It will prompt all the configured mapping to select from. Choose the mapping from the prompt and from the next operation, files and folder sync will be happening on the selected mapping.
Diff Remote File
We can check the difference between local and remote files using the “Diff Remote File” Option. I created a file dummy.py in the remote machine and added
print(“Hello world”) but it is not synced locally. Now if I try to see the changes with a remote file it will print the changes I made.
There are default key bindings we can use instead of hovering through the menus all the time. To know the list of key bindings PREFERENCES → PACKAGE SETTINGS → SFTP → KEY BINDINGS DEFAULT.
We can also define our own set of key bindings which will override the default bindings. To create user-defined key bindings for SFTP PREFERENCES → PACKAGE SETTINGS → SFTP → KEY BINDINGS → USER.
So far in this article, we have seen how to install the SFTP package to transfer files between local and remote machines through file transfer protocol. We have also seen how to upload/Sync folders from Local to remote and remote to local machines. Default keybindings and how to set user-defined key bindings.
2 thoughts on “How to Setup Sublime Text sFTP for Remote Development”
Hello, I installed sftp in the sublime text but It doesn’t connect to the server on the cloud, but if I use the command line commands everything work well:
but with the configuration in the sublime text, I can’t..
What is the error you are getting when connecting to the cloud server?
You can press
CTRL + ~to view the logs during connection.