Sublime SFTP

One of the most common requests from users and potential users is to be able to work on a remote server in a way that the files and folders appear in the sidebar. Below is information about the proposed Sublime Text sidebar API, along with a couple of current solutions. Of the two current solutions, each one has pros and cons, so be sure to check out both.

If your remote editing needs are few and far between, the Server Workflow might be the right answer for you. If you need to work with lots of remote files, you’ll probably want to read on.

The Proposed Solution (Not Full Featured, 100% Automated, No Performance Issues)

Currently I have a request into the developer of Sublime Text (Jon Skinner) to add a sidebar API so that it will be possible to view remote files and folders in the sidebar. However, even if/when this does become possible, it will not be possible to use Goto File and Search in Folder with this because of the performance characteristics of the FTP and SFTP protocols. Sublime Text is fast because it caches information in memory and uses filesystem notifications of your OS to learn about file changes.

There are a couple of ideas on the Sublime Text User Echo site that you can vote on if you would like to see the Sidebar API added: Side Bar API and FTP and SFTP with browsing….

The Sublime SFTP Solution (Full Featured, Mostly Automated, No Performance Issues)

The current solution that is available to work on remote files involves creating a local copy of them. However, the local files are basically used as a facade for Sublime Text to perform standard file opertions such as the Goto commands. By using a number of features of Sublime SFTP, the local files will be automatically replaced with remote files when viewing and editing them.

Setup

In order for this process to work, you’ll need to create a local folder to store the files in, and then configure Sublime SFTP with the specific options to make remote editing (mostly) seamless.

  1. Create a local folder on your machine
  2. Add the folder to Sublime Text.

    Tip: save the opened folder as a project through the Project menu. Saving it as a project just lets you easily switch between projects using ctrl+alt+p/cmd+alt+p.

  3. Right-click on the folder in the Sublime Text sidebar and select SFTP > Map to Remote…
  4. Set the type, host, user and password options as appropriate for your server. Then also configure the following options:

    save_before_upload
    true Ensures if a trigger an upload that the file will be saved first.
    upload_on_save
    true Ensures a file is sent to the server whenever you save it.
    sync_down_on_open
    true Causes Sublime SFTP to download the file (if the server version is newer) whenever you open a file.
    confirm_sync
    true Turns off the confirmation of performing sync operations when opening a file locally.
    ignore_regexes
    Add any folder names you don’t want to sync, such as an uploads or cache folder. Each entry in the list is a regular expression, so you can either type a folder name, e.g. "/cache/" or a pattern "google.*\\.html".
    extra_list_connections
    4 Causes four extra FTP/SFTP connections to the server to be opened when determining what files need to be synced. Since the process of determining what files to sync requires listing the sub-contents of every sub-folder, and since the FTP and SFTP protocols are fairly slow in terms of the back and forth required to list a folder, this makes a huge difference in how long sync operations take. My testing indicates that using 4 extra connections causes the discovery part of the sync to happen in 1/4 of the time! Depending on your server configuration, you may even be able to use more.
    preserve_modification_times
    true This ensures that the file timestamps for your machine and the remote machine are kept in sync so that the sync operations can properly compare them. While not every FTP server supports this, it is really only important in this workflow that your local modification times are kept in sync with the server.
  5. Download the contents of the remote folder to your machine by right-clicking your local folder and selecting SFTP > Download Folder

Workflow

Once the setup is complete, the workflow for working on a server goes like this:

  1. When you start working on the project for the day, open your project and Sync Remote -> Local:
    a. Right-click your root folder and select SFTP > Sync Remote -> Locale; or
    b. Press ctrl+alt+u, ctrl+alt+d (Windows/Linux) / cmd+ctrl+u, cmd+ctrl+d (OS X)
  2. Open any file using Sublime Text. As soon as a tab is created for the file (i.e. you are no longer previewing it), Sublime SFTP will check to see if a newer version is on the server and download it.
  3. Whenever you save a file, it will be automatically uploaded.

Conclusion

Hopefully this provides a useful workflow for those of you that are required to work off of a server. If you have any suggestions for Sublime SFTP, or this workflow, please shoot me an email at support@wbond.net.

Remote Filesystem Solutions (Full Featured, 100% Automated, Performance Issues)

In addition to the solution available via Sublime SFTP and automated uploads and sync operations, it is possible to use a number of different software packages to present a remote FTP or SFTP server as a local filesystem.

For some users, these solutions are great, other users have complained about performance issues. This is usually because when you open a file with one of these packages, it can't be read until it is fully downloaded which gives a lag to the interface. Additionally, Sublime Text has to download every file in order to do things like folder searches. However, don’t take my word for it, just try one out!