# Make SFTP/SSHFS great again This page serves as a tentative list of resources to study and experiment with the SFTP protocol after its original specification draft having expired and in the process of being forgotten. My hope is that SFTP will be ~~great~~ widely-adopted again. My specific use cases are: * To communicate in SFTP with web apps * To bridge server-side file-system-based programs with web clients interacting with the same file tree # Browser as a SFTP client ## websocketfs (modern) Check out websocketfs: https://github.com/sagemathinc/websocketfs * It comes with two packages `websocket-sftp` and `websocketfs`, the former for the protocol (transport layer) and the latter for FUSE integration. * Uses libfuse2 bindings to Node, eliminating the need for sshfs > Sadly I cannot find any libfuse3 binding in JS ecosystem for now... I am now maintaining [a fork of websocketfs](https://github.com/qbane/websocketfs), aiming to specifically enhance the `websocket-sftp` package. ## sftp-ws (legacy) The original sftp-ws, SFTP over WebSocket: https://github.com/lukaaash/sftp-ws > There is a ~~modern~~ fork (?) https://github.com/Inveniem/sftp-ws > (merely update the package so that it can be built using up-to-date toolchain) To use it, a bridge program [`vfs`](https://github.com/lukaaash/vfs) is needed: Server: ```js const SFTP = require('./lib/sftp') const server = new SFTP.Server({ port: 8888, virtualRoot: '.', readOnly: true, }) ``` Client: `npx vfs ws://localhost ./local --path PATH` Note that you need to patch the code to include a port argument and pass to sshfs with `-p PORT`. Under the hood, it invokes `sshfs localhost:PATH -o slave` and communicate with it through the WebSocket channel. (The option is aliased as `passive` in later versions that is more inclusive) ## The interoperability This is reversible! You can make the SSH "client" act as an SFTP server. All you need is a reverse tunnel `ssh -R xxxx:localhost:yyyy`. [Like this](https://superuser.com/questions/616182/how-to-mount-local-directory-to-remote-like-sshfs). **I think this is the best part of SSHFS: The interoperability. You can mirror part of a file system to other machines as long as you have a working SSH connection.** # GIO? > Well, there is "gio mount sftp://USER@XYZ" after which you can access the files under "/run/user/1000/gvfs/sftp:host=XYZ,user=USER/SOME_PATH/…" > goombacloud -- https://news.ycombinator.com/item?id=31813979. The support [looks promising](https://gitlab.gnome.org/GNOME/gvfs/-/blob/master/daemon/gvfsbackendsftp.c). Cannot make it work under MacOS. Despite GVFS has monitor mechanism, it is not implemented in most protocols. # Green End SFTP Server Website: http://www.greenend.org.uk/rjk/sftpserver/ Repository: https://github.com/ewxrjk/sftpserver It is a well-maintained SFTP server with a reasonable client for some ad-hoc scriptings. Supports all SFTP protocol versions from v3 to v6! You can also find some background, [extensions](http://www.greenend.org.uk/rjk/sftp/sftpversions.html#extensions), comparison between protocol version, and more on its website. ## SFTP over WebSocket When experimenting with "SFTP over WebSocket" (that's another story), I find it useful to pair [a patched Green End SFTP Server](https://github.com/qbane/sftpserver/) with [an also patched websocat](https://github.com/vi/websocat/commit/250d5df532349c1b1fec9a922f3d9fe743606c92); commands shown as below: ```bash! # WS server websocat -b --exit-on-eof ws-l:127.0.0.1:8888 lengthprefixed:tcp:127.0.0.1:9999 # SFTP server gesftpserver -H 127.0.0.1 -L 9999 --debug --websocat ``` The length-prefixed message framing technique is redundant for SFTP, but it works anyway. # Active forks of SSHFS Because the upstream repo is archived, the development work takes place in various forks (not sorted in any order): * https://github.com/rozhuk-im/sshfs -- several patch branches ([diff](https://github.com/libfuse/sshfs/compare/master...rozhuk-im:sshfs:master)) * https://github.com/deadbeefsociety/sshfs -- very active, also including some patches! ([diff](https://github.com/libfuse/sshfs/compare/master...deadbeefsociety:sshfs:main)) * https://github.com/neunenak/sshfs -- including a rust port! * **https://github.com/stevenxxiu/sshfs -- supports and only supports SFTP v6!** The full fork scan on GitHub, retrieved 2023/8/29: <details> |Repo |Stars|Forks|Ahead|Behind|Last Push | |------------------------|----:|----:|----:|-----:|----------| |[deadbeefsociety/sshfs](https://github.com/deadbeefsociety/sshfs) |26 |3 |37 |0 |2023-03-11| |[stevenxxiu/sshfs](https://github.com/stevenxxiu/sshfs) |16 |0 |86 |0 |2023-05-07| |[neunenak/sshfs](https://github.com/neunenak/sshfs) |12 |1 |12 |0 |2022-11-26| |[andy0130tw/sshfs](https://github.com/andy0130tw/sshfs) |7 |0 |6 |0 |2022-06-16| |[rozhuk-im/sshfs](https://github.com/rozhuk-im/sshfs) |1 |0 |13 |0 |2023-05-02| |[steamboatid/sshfs](https://github.com/steamboatid/sshfs) |1 |0 |3 |0 |2022-09-10| |[njzhangyifei/sshfs](https://github.com/njzhangyifei/sshfs) |1 |0 |23 |136 |2020-10-08| |[smartdisk/sshfs](https://github.com/smartdisk/sshfs) |0 |0 |2 |0 |2023-07-13| |[a1346054/sshfs](https://github.com/a1346054/sshfs) |0 |0 |3 |0 |2022-09-03| |[tesla232/sshfs](https://github.com/tesla232/sshfs) |0 |0 |2 |0 |2022-08-01| |[g-easy/sshfs](https://github.com/g-easy/sshfs) |0 |0 |1 |2 |2022-02-15| |[peterbelm/sshfs](https://github.com/peterbelm/sshfs) |0 |0 |2 |13 |2021-01-19| |[gururajrkatti/sshfs](https://github.com/gururajrkatti/sshfs) | 0 |0 |2 |13 |2020-12-31| |[martinetd/sshfs](https://github.com/martinetd/sshfs) |0 |0 |2 |24 |2019-11-29| |[nnsuite/tizenport-sshfs](https://github.com/nnsuite/tizenport-sshfs) |0 |1 |23 |136 |2019-07-17| |[wooksong/tizenport-sshfs](https://github.com/wooksong/tizenport-sshfs)|0 |0 |97 |23 |2019-06-30| |[mssalvatore/sshfs](https://github.com/mssalvatore/sshfs) |0 |0 |2 |45 |2019-04-13| |[sdcloudt/sshfs](https://github.com/sdcloudt/sshfs) |0 |0 |1 |56 |2018-10-28| |[iori-yja/sshfs](https://github.com/iori-yja/sshfs) |0 |0 |8 |147 |2017-06-04| |[Cloudxtreme/sshfs-1](https://github.com/Cloudxtreme/sshfs-1) | 0 |0 |1 |166 |2016-06-15| |[BTBurke/sshfs](https://github.com/BTBurke/sshfs) |0 |0 |1 |172 |2016-02-27| </details> # Useful links * **Reference tables organized for myself**: https://hackmd.io/BplmLAiDSZekdat-G8-gqA * Chromium OS has SSHFS inside! If you have access to a recent Chrome OS device, you may have seen a text like "SSHFS is launching" during the initialization phase of its Linux subsystem. https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/main/net-fs/sshfs/ * https://wiki.samba.org/index.php/Editing_files_locally_on_server:_interoperability --- My comment: SMB has a file alternation monitor, wondering if this is doable in SFTP/SSHFS context?