Skip to main content

SFTP filesystem

Spectranext can mount an SFTP server as a filesystem. This lets you browse files on a computer or server, load TAP files, and read or write data using the usual Spectranet commands. The connection is encrypted using SSH.

SFTP support is a Spectranext extension and is not available on classic Spectranet. Unlike the HTTP(s) filesystem, it supports writing files and lists directories directly, without index.txt files.

Before you start​

Connect Spectranext to Wi-Fi. You also need a reachable SSH server with SFTP enabled, a user account, and access to the directory you want to mount. For the password examples below, the server must allow password authentication.

Mount an SFTP directory​

Use a URL containing your username, password, server address, and directory:

%mount "sftp://demo:password@192.168.1.42/home/demo/games/"
%cat

Replace the example credentials and address with your own. The command chooses a free mount slot and selects it automatically; %cat lists the mounted directory.

The directory in the URL becomes the root of this mount. In this example, game.tap refers to /home/demo/games/game.tap on the server. The directory must already exist and be accessible to your account.

The default SSH port is 22. For a server using another port, include it after the hostname:

%mount "sftp://demo:password@192.168.1.42:2222/home/demo/games/"

Usernames and passwords containing URL separators must be percent-encoded. For example, use %40 for @, %3A for :, and %25 for % in those fields.

Passwords in BASIC programs

The connection is encrypted, but the password remains visible in the mount command and any BASIC program containing it. Do not publish programs with your credentials included.

Choose a mount slot​

To keep the default local filesystem in slot 0, you can explicitly use slot 3:

%mount 3, "sftp://demo:password@192.168.1.42/home/demo/games/"
%fs 3
%cat

If slot 3 is already occupied, unmount it first with %umount 3. The explicit mount form needs %fs 3 to select it.

Load a TAP file​

With the SFTP mount selected:

%tapein "game.tap"
LOAD ""

The TAP is read from the server through the normal tape input mechanism. Use %tapein for remote files; %xtapein reads Spectranext's local storage instead.

Read and write files​

Use the same file commands as with other mounted filesystems. For example, create a text file on the server:

%fopen #4, "notes.txt", "w"
PRINT #4; "Hello from my Spectrum"
%close #4

Opening an existing file with "w" replaces its contents. Changes are made directly on the server and are subject to your account's permissions.

SFTP supports reading, writing, seeking, directory listings, creating and removing directories, renaming and deleting files, and changing file permissions. Programs using the Spectranet filesystem API can use the mounted SFTP filesystem too.

Server identity​

On the first SFTP connection to a server address and port, Spectranext automatically remembers its SSH host key. Later connections must present the same key; a changed key causes the connection to fail.

There is no interactive host-key confirmation during an SFTP mount. Make the first connection on a network you trust. If mounting stops working after the server is rebuilt or its SSH keys change, the stored server identity may no longer match.

Finish using the mount​

Close your files, then unmount the slot to disconnect:

%umount 3
%fs 0

This example assumes SFTP was mounted in slot 3 and the default local filesystem is still in slot 0.

If mounting fails​

Check the server address and port, Wi-Fi connection, username and password, and whether SFTP is enabled. Also check that the directory in the URL exists and your account can access it. A successful SSH terminal login alone does not guarantee that the server allows SFTP.