How to Setup Sublime Text sFTP for Remote Development

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 PACKAGESFTP.

Install sFTP in Sublime Text
Install sFTP in Sublime Text

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.

Sublime Text sFTP Options
Sublime Text sFTP Options

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 folderSFTP/FTPMap to Remote.

Configure Remote Setup for sFTP
Configure Remote Setup for sFTP

The sftp-config.json file will be created in the project folder which holds the remote configuration settings.

Remote Configuration Settings
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”.

sFTP Protocol
sFTP Protocol

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.

Remote Host Settings
Remote Host Settings

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”.

SSH Authentication
SSH Authentication

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”.

Configure Remote Path
Configure Remote Path

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 /home/tecmint now.

Project Home Directory
Project Home Directory

Right-click on project folder → SFTP/FTP.

sFTP Operations
sFTP Operations

Sublime Text sFTP Operations and Usage

Let’s break down all the options.

Upload Folder

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.

Upload Folder
Upload Folder

Both the files in the local directory are uploaded to the remote directory. The sftp-config.json files will be skipped.

Uploaded Files
Uploaded Files
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.

Rename Folders
Rename Folders
Delete Local and Remote Folder

This option will delete the current project folder from both remote machine and local machine along with sftp-config.json file.

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.

Local to Remote
Local to Remote
Remote → Local

Sync remote files locally and remove any extra files in the local project folder.

Both Directions

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.

Browse Remote

We can access the remote files and folders other than the project directory using the browse remote option.

Browse Remote
Browse Remote
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.

Multiple Mapping
Multiple Mapping

We can now decide which remote mapping to choose from.

Switch Mapping
Switch Mapping

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.

Select Mapping
Select 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.

Diff Remote File
Diff Remote File
Key Bindings

There are default key bindings we can use instead of hovering through the menus all the time. To know the list of key bindings PREFERENCESPACKAGE SETTINGSSFTPKEY 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 PREFERENCESPACKAGE SETTINGSSFTPKEY BINDINGSUSER.

Key Bindings
Key Bindings

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.

Karthick
A passionate software engineer who loves to explore new technologies. He is a public speaker and loves writing about technology, especially about Linux and open source.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

2 thoughts on “How to Setup Sublime Text sFTP for Remote Development”

  1. 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:

    $ sftp -i keyssh -P 22 [email protected]
    

    but with the configuration in the sublime text, I can’t..

    {
        // The tab key will cycle through the settings when first created
        // Visit https://codexns.io/products/sftp_for_subime/settings for help
        
        // sftp, ftp or ftps
        "type": "sftp",
    
        "sync_down_on_open": true,
        "sync_same_age": true,
        
        "host": "162.44.47.129",
        "user": "root",
        //"password": " ",
        "port": "22",
        
        "remote_path": "/root",
        //"file_permissions": "664",
        //"dir_permissions": "775",
        
        //"extra_list_connections": 0,
    
        "connect_timeout": 20,
        //"keepalive": 120,
        //"ftp_passive_mode": true,
        //"ftp_obey_passive_host": false,
        "ssh_key_file": "/home/sodex/llaves/jenrrysh",
        //"sftp_flags": ["-F", "/path/to/ssh_config"],
        
        //"preserve_modification_times": false,
        //"remote_time_offset_in_hours": 0,
        //"remote_encoding": "utf-8",
        //"remote_locale": "C",
        //"allow_config_upload": false,
    }
    
    Reply
    • What is the error you are getting when connecting to the cloud server?

      You can press CTRL + ~ to view the logs during connection.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.