Standard library · Network

ssh

SSH connections, running a command on a server, and working with files over SFTP.

import ssh

This package is an SSH client written in Salam and needs neither OpenSSH nor any other library. Make a Config with the host and the user, pick the login method, and connect with Connect; then run a command with Exec, or move files with SftpOpen. It suits automating deployments, backups and checks across a fleet of servers. It is a client only; for plain file transfer with an FTP server see ftp.

The host key is checked against the known_hosts file, the way ssh itself does. The buffer and reader functions build and read the data format of the SSH protocol; an ordinary program does not need them.

What it supports, and what it does not:

  • Keys must be RSA, in the OpenSSH format, without a passphrase. Ed25519 and ECDSA keys, the default of recent ssh-keygen, are not read. Make a key for automation with ssh-keygen -t rsa -b 4096 -N "" -f deploy_key; a password login with WithPassword also works.
  • The server needs an RSA host key; a server that offers only Ed25519 or ECDSA host keys cannot be checked and the connection fails.
  • Key exchange is curve25519 or Diffie-Hellman group 14, and the ciphers are aes128-ctr and aes256-ctr, which every OpenSSH server accepts. There is no agent support and no port forwarding; an interactive shell with a terminal is available through NewSession, RequestPty and Shell.
  • Each Exec is a fresh shell: a cd or an exported variable does not carry over to the next call.

Run a deployment, step by step

Exec runs one command and waits for it, returning its standard output, its standard error and the exit code in an ExecResult. Each call opens a new channel, so a cd in one command does not carry over to the next; join commands with && when they belong together. A deployment is then a list of steps that stops at the first one whose exit code is not zero.

ssh-deploy.salam
import ssh
import str

func run_steps(client &: ssh.Client, steps: Vector<str>): bool:
    each step in steps:
        r := ssh.Exec(client, step)
        if not r.ok or r.exit_code != 0:
            println "FAILED:", step
            println str.Trim(r.stderr)
            ret false
        end
        println "ok:", step
    end
    ret true
end

func main:
    mut cfg := ssh.NewConfig("app1.example.com", ssh.DefaultPort, "deploy")
    if not ssh.WithKeyFile(cfg, "/home/deploy/.ssh/id_rsa"):
        println "cannot read the key file"
        ret 1
    end
    ssh.WithHostKeyMode(cfg, ssh.HOSTKEY_MODE_STRICT)
    mut client := ssh.Connect(cfg)
    if not ssh.Ok(client):
        println "connect failed:", ssh.Error(client)
        ret 1
    end

    mut steps := Vector {} as Vector<str>
    steps.Push("cd /srv/app && git fetch --quiet && git checkout --quiet v2.4.0")
    steps.Push("cd /srv/app && ./salam build --release")
    steps.Push("sudo systemctl restart app")
    steps.Push("systemctl is-active app")
    done := run_steps(client, steps)
    ssh.Close(client)
    if not done:
        ret 1
    end
    ret 0
end

This needs a real server, so it is only checked here. WithKeyFile only reads the file, so it returns false when the path is wrong; a key the package cannot use makes Connect fail instead. For a command that runs for a long time and whose output you want as it comes, such as tail -f, use NewSession, Start and ReadStep with DrainOutput instead, as the example in the reference shows.

Pull a backup over SFTP

SSH and SFTP share one connection: run the command that writes the file with Exec, then open SFTP on the same client and fetch it. Stat gives the size, Download copies the file, and Remove cleans up on the server once the copy has arrived. For whole directories there are UploadDir, DownloadDir and MkdirAll.

ssh-backup.salam
import ssh

func main:
    mut cfg := ssh.NewConfig("db.example.com", 22, "backup")
    _ := ssh.WithKeyFile(cfg, "/home/backup/.ssh/id_rsa")
    mut client := ssh.Connect(cfg)
    if not ssh.Ok(client):
        println "connect failed:", ssh.Error(client)
        ret 1
    end

    remote := "/tmp/shop-backup.sql.gz"
    dump := ssh.Exec(client, "pg_dump shop | gzip > " + remote)
    if dump.exit_code != 0:
        println "pg_dump failed:", dump.stderr
        ssh.Close(client)
        ret 1
    end

    mut sftp := ssh.SftpOpen(client)
    info := ssh.Stat(client, sftp, remote)
    println "dump size on the server:", info.size, "bytes"
    if ssh.Download(client, sftp, remote, "shop-backup.sql.gz"):
        println "downloaded"
        _ := ssh.Remove(client, sftp, remote)
    else:
        println "download failed:", ssh.Error(client)
    end
    ssh.SftpClose(client, sftp)
    ssh.Close(client)
    ret 0
end

Host keys and known_hosts

The host key is how the client knows it is talking to the right machine and not to someone in between. The mode decides what happens with a key that is not in known_hosts yet. HOSTKEY_MODE_STRICT refuses it, which is right for automation: add the key once by hand, then every later change is an error you want to hear about. HOSTKEY_MODE_ACCEPT_NEW is the default; it records a new key the first time and refuses a changed one later, like StrictHostKeyChecking=accept-new in OpenSSH. HOSTKEY_MODE_INSECURE checks nothing and belongs only in tests.

ssh-host-keys.salam
import ssh

func attempt(mode: int, label: str):
    mut cfg := ssh.NewConfig("new-server.example.com", 22, "admin")
    ssh.WithPassword(cfg, "first-login-password")
    ssh.WithKnownHostsPath(cfg, "known_hosts")
    ssh.WithHostKeyMode(cfg, mode)
    mut client := ssh.Connect(cfg)
    if ssh.Ok(client):
        println label, "connected, host key", ssh.HostKeyFingerprint(client)
        ssh.Close(client)
    else:
        println label, "refused:", ssh.Error(client)
    end
end

func main:
    attempt(ssh.HOSTKEY_MODE_STRICT, "strict, empty known_hosts:")
    attempt(ssh.HOSTKEY_MODE_ACCEPT_NEW, "accept-new, first time:")
    attempt(ssh.HOSTKEY_MODE_STRICT, "strict, key now recorded:")
end

With an empty known_hosts the first, strict attempt is refused, the second records the key, and the third, strict again, now connects. HostKeyFingerprint returns the same SHA-256 fingerprint that ssh-keygen -lf prints, so you can compare it with what the server's administrator gave you. The client checks the server's RSA host key (rsa-sha2-256, rsa-sha2-512 or ssh-rsa), so the server needs one; a default OpenSSH install usually has it.

Many hosts from one list

A Config is a plain value, so it is easy to build one per line of an inventory and keep the same rules for all of them: the same user, the same known_hosts file and strict checking. Nothing connects until Connect is called, so the program below runs without a network.

ssh-inventory.salam
import ssh
import str
import conv

func parse(line: str): ssh.Config:
    fields := str.Split(line, " ")
    mut port := ssh.DefaultPort
    mut host := fields.Get(0)
    if str.Contains(host, ":"):
        parts := str.Split(host, ":")
        host = parts.Get(0)
        port = conv.AtoiOr(parts.Get(1), port)
    end
    mut cfg := ssh.NewConfig(host, port, fields.Get(1))
    ssh.WithHostKeyMode(cfg, ssh.HOSTKEY_MODE_STRICT)
    ssh.WithKnownHostsPath(cfg, "/etc/deploy/known_hosts")
    ret cfg
end

func main:
    inventory := "web1.example.com deploy\nweb2.example.com deploy\nbastion.example.com:2222 ops"
    each line in str.Split(inventory, "\n"):
        cfg := parse(line)
        println cfg.user + "@" + cfg.host, "port", cfg.port, "strict:", cfg.hostkey_mode == ssh.HOSTKEY_MODE_STRICT
    end
end
Outputdeploy@web1.example.com port 22 strict: true deploy@web2.example.com port 22 strict: true ops@bastion.example.com port 2222 strict: true

To run the same command on all hosts, loop over the configs, connect, Exec and Close. If one host is down, Ok is false for that client and Error says why, and the loop can go on to the next.

Types

Config

struct Config
The configuration of an SSH connection.
NameTypeDescription
hoststr = ""The host.
portint = 22The port; 22 by default.
userstr = ""The user name.
passwordstr = ""The password.
use_passwordbool = falseLog in with a password.
key_pemstr = ""The private key as text.
use_keybool = falseLog in with a key.
hostkey_modeint = 1The host key check mode.
known_hosts_pathstr = ""The path of the known_hosts file.
ssh-Config.salam
import ssh

func main:
    mut cfg := ssh.NewConfig("example.com", ssh.DefaultPort, "deploy")
    println cfg.host, cfg.port, cfg.user, cfg.hostkey_mode == ssh.HOSTKEY_MODE_ACCEPT_NEW
    ssh.WithPassword(cfg, "s3cret")
    println cfg.use_password, cfg.use_key
    ssh.WithKeyPEM(cfg, "-----BEGIN OPENSSH KEY-----")
    println cfg.use_key, cfg.key_pem.Len() > 0
    println ssh.WithKeyFile(cfg, "/nonexistent/id_rsa")
    ssh.WithHostKeyMode(cfg, ssh.HOSTKEY_MODE_STRICT)
    ssh.WithKnownHostsPath(cfg, "/home/deploy/.ssh/known_hosts")
    println cfg.hostkey_mode, cfg.known_hosts_path
    println ssh.HOSTKEY_MODE_INSECURE, ssh.ClientVersion
end
Outputexample.com 22 deploy true true false true true false 2 /home/deploy/.ssh/known_hosts 0 SSH-2.0-Salam_1.0

Session

struct Session
One session over the connection: one command or one shell.
NameTypeDescription
chChannelThe SSH channel.
okbool = falseThe session opened.
ssh-Exec.salam
import ssh

func main:
    mut cfg := ssh.NewConfig("server.example.com", 22, "deploy")
    _ := ssh.WithKeyFile(cfg, "/home/deploy/.ssh/id_rsa")
    mut client := ssh.Connect(cfg)
    if not ssh.Ok(client):
        println "error:", ssh.Error(client)
        ret
    end
    println "host key:", ssh.HostKeyFingerprint(client)

    r := ssh.Exec(client, "uname -a")
    println r.ok, r.exit_code, r.stdout, r.stderr
    r2 := ssh.RunCommand(client, "df -h /")
    println r2.stdout

    mut tail := ssh.NewSession(client)
    _ := ssh.RequestPty(tail, client, "xterm", 120, 40)
    if ssh.Start(tail, client, "tail -f /var/log/app.log"):
        repeat 10:
            _ := ssh.ReadStep(tail, client)
            print ssh.DrainOutput(tail)
            print ssh.DrainStderrOutput(tail)
        end
    end
    ssh.CloseSession(tail, client)

    mut shell := ssh.NewSession(client)
    if ssh.Shell(shell, client):
        _ := ssh.WriteInput(shell, client, "echo hello\nexit\n")
        ssh.CloseInput(shell, client)
        code := ssh.Wait(shell, client)
        println code, ssh.ExitCode(shell), ssh.SessionClosed(shell)
        println ssh.Output(shell), ssh.StderrOutput(shell)
    end
    ssh.CloseSession(shell, client)

    probe := ssh.Dial(cfg)
    println ssh.Ok(probe)
    println ssh.Reconnect(client)
    println ssh.SelfTest()
    ssh.Close(client)
end

ExecResult

struct ExecResult
The result of running one command.
NameTypeDescription
stdoutstr = ""The output.
stderrstr = ""The error output.
exit_codeint = -1The exit code.
okbool = falseThe command ran.

The example for this item is shown with the ones above: ssh-Exec.salam

Sftp

struct Sftp
An SFTP session for working with the files on the server.
NameTypeDescription
chChannelThe channel.
okbool = falseIt opened.
next_idu32 = 1The number of the next request.
ssh-Sftp.salam
import ssh

func main:
    mut cfg := ssh.NewConfig("files.example.com", 22, "ali")
    ssh.WithPassword(cfg, "s3cret")
    mut client := ssh.Connect(cfg)
    mut sftp := ssh.SftpOpen(client)
    if not sftp.ok:
        println ssh.Error(client)
        ret
    end
    println ssh.MkdirAll(client, sftp, "/backup/2026/09")
    println ssh.Upload(client, sftp, "report.pdf", "/backup/2026/09/report.pdf")
    println ssh.UploadDir(client, sftp, "site", "/var/www/site")
    if ssh.Exists(client, sftp, "/backup/2026/09/report.pdf"):
        info := ssh.Stat(client, sftp, "/backup/2026/09/report.pdf")
        println info.name, info.size, info.is_dir, info.permissions
    end
    each info in ssh.ListDir(client, sftp, "/backup"):
        println info.name, info.is_dir
    end
    println ssh.IsLink(client, sftp, "/current"), ssh.Lstat(client, sftp, "/current").name
    _ := ssh.Download(client, sftp, "/etc/hostname", "hostname.txt")
    _ := ssh.DownloadDir(client, sftp, "/var/log/app", "logs")
    _ := ssh.Rename(client, sftp, "/tmp/a", "/tmp/b")
    _ := ssh.Remove(client, sftp, "/tmp/b")
    _ := ssh.Mkdir(client, sftp, "/tmp/x")
    _ := ssh.Rmdir(client, sftp, "/tmp/x")
    _ := ssh.RemoveAll(client, sftp, "/tmp/old")
    ssh.SftpClose(client, sftp)
    ssh.Close(client)
end

SftpFileInfo

struct SftpFileInfo
The information about one file.
NameTypeDescription
namestr = ""The name.
sizei64 = 0The size in bytes.
is_dirbool = falseIt is a directory.
permissionsu32 = 0The permissions as a Unix number.

The example for this item is shown with the ones above: ssh-Sftp.salam

Client

struct Client
One SSH connection.
NameTypeDescription
transportTransportThe encrypted layer.
cfgConfigThe configuration.
connectedbool = falseIt is connected.
errmsgstr = ""The error message.

The example for this item is shown with the ones above: ssh-Exec.salam

Constants and variables

DefaultPort

const DefaultPort: i32 = 22
The default SSH port: 22.

The example for this item is shown with the ones above: ssh-Config.salam

ClientVersion

const ClientVersion: str = "SSH-2.0-Salam_1.0"
The version string the client sends at the start of the connection.

The example for this item is shown with the ones above: ssh-Config.salam

HOSTKEY_MODE_INSECURE

const HOSTKEY_MODE_INSECURE: i32 = 0
Host key mode: do not check it; the connection is then open to a man in the middle attack.

The example for this item is shown with the ones above: ssh-Config.salam

HOSTKEY_MODE_ACCEPT_NEW

const HOSTKEY_MODE_ACCEPT_NEW: i32 = 1
Host key mode: accept a new host and record it in known_hosts, but reject a changed key; the default.

The example for this item is shown with the ones above: ssh-Config.salam

HOSTKEY_MODE_STRICT

const HOSTKEY_MODE_STRICT: i32 = 2
Host key mode: only hosts already in known_hosts.

The example for this item is shown with the ones above: ssh-Config.salam

Functions

NewConfig

func NewConfig(host: str, port: int, user: str): Config
A new configuration for a host, port and user.

The example for this item is shown with the ones above: ssh-Config.salam

WithPassword

func WithPassword(cfg &: Config, password: str)
Sets up login with a password.

The example for this item is shown with the ones above: ssh-Config.salam

WithKeyFile

func WithKeyFile(cfg &: Config, path: str): bool
Reads the private key from a file and switches the login to that key; false when the file could not be read or is empty. The key must be an unencrypted RSA key in the OpenSSH format; any other key is only refused at Connect.

The example for this item is shown with the ones above: ssh-Config.salam

WithKeyPEM

func WithKeyPEM(cfg &: Config, pem: str)
Takes the private key from text, for a key kept in an environment variable or a secret store; the same key rules as WithKeyFile.

The example for this item is shown with the ones above: ssh-Config.salam

WithHostKeyMode

func WithHostKeyMode(cfg &: Config, mode: int)
Sets the host key check mode.

The example for this item is shown with the ones above: ssh-Config.salam

WithKnownHostsPath

func WithKnownHostsPath(cfg &: Config, path: str)
Uses another known_hosts file.

The example for this item is shown with the ones above: ssh-Config.salam

NewSession

func NewSession(client &: Client): Session
Opens a new session.

The example for this item is shown with the ones above: ssh-Exec.salam

RequestPty

func RequestPty(session &: Session, client &: Client, term: str, cols: int, rows: int): bool
Asks for a pseudo terminal of the given type and size; for commands that need a terminal.

The example for this item is shown with the ones above: ssh-Exec.salam

Start

func Start(session &: Session, client &: Client, cmd: str): bool
Starts a command in the session and does not wait.

The example for this item is shown with the ones above: ssh-Exec.salam

Shell

func Shell(session &: Session, client &: Client): bool
Starts the shell of the user.

The example for this item is shown with the ones above: ssh-Exec.salam

Wait

func Wait(session &: Session, client &: Client): int
Waits for the command to finish and returns the exit code.

The example for this item is shown with the ones above: ssh-Exec.salam

ReadStep

func ReadStep(session &: Session, client &: Client): bool
Reads whatever data has arrived, once; for reading the output as it comes.

The example for this item is shown with the ones above: ssh-Exec.salam

Output

func Output(session: Session): str
All the output so far.

The example for this item is shown with the ones above: ssh-Exec.salam

StderrOutput

func StderrOutput(session: Session): str
All the error output so far.

The example for this item is shown with the ones above: ssh-Exec.salam

DrainOutput

func DrainOutput(session &: Session): str
Returns the new output and takes it out of the buffer.

The example for this item is shown with the ones above: ssh-Exec.salam

DrainStderrOutput

func DrainStderrOutput(session &: Session): str
Returns the new error output and takes it out.

The example for this item is shown with the ones above: ssh-Exec.salam

ExitCode

func ExitCode(session: Session): int
The exit code; -1 when it has not finished yet.

The example for this item is shown with the ones above: ssh-Exec.salam

SessionClosed

func SessionClosed(session: Session): bool
The session has been closed.

The example for this item is shown with the ones above: ssh-Exec.salam

WriteInput

func WriteInput(session &: Session, client &: Client, data: str): bool
Writes to the input of the command.

The example for this item is shown with the ones above: ssh-Exec.salam

CloseInput

func CloseInput(session &: Session, client &: Client)
Closes the input, so the command knows the data has ended.

The example for this item is shown with the ones above: ssh-Exec.salam

CloseSession

func CloseSession(session &: Session, client &: Client)
Closes the session.

The example for this item is shown with the ones above: ssh-Exec.salam

Exec

func Exec(client &: Client, cmd: str): ExecResult
Runs a command and waits for it to finish.

The example for this item is shown with the ones above: ssh-Exec.salam

NewBuf

func NewBuf(cap0: int): Buf
An empty buffer for building SSH protocol messages.
ssh-Wire.salam
import ssh

func main:
    mut b := ssh.NewBuf(64)
    ssh.BufPutByte(b, 20)
    ssh.BufPutUint32(b, 7 as u32)
    ssh.BufPutUint64(b, 9 as u64)
    ssh.BufPutBool(b, true)
    ssh.BufPutStringStr(b, "ssh-ed25519,rsa-sha2-256")
    ssh.BufPutString(b, "abc" as void*, 3)
    ssh.BufPutBytes(b, "xy" as void*, 2)
    ssh.BufPutZeros(b, 2)
    ssh.BufPutMpintBytes(b, "\x80" as void*, 1)
    println b.len

    mut r := ssh.ReaderFromBuf(b)
    println ssh.RGetByte(r), ssh.RGetUint32(r), ssh.RGetUint64(r), ssh.RGetBool(r)
    names := ssh.RGetNameList(r)
    println names, ssh.NameListContains(names, "rsa-sha2-256")
    println ssh.RGetStringAsStr(r)
    ssh.RSkip(r, 4)
    println ssh.RRemaining(r)
    n := ssh.RGetMpintView(r)
    println n.len, ssh.RRemaining(r)

    println ssh.NegotiateFirstMatch("aes256-ctr,aes128-ctr", "aes128-ctr,aes256-ctr")
    println ssh.ConstantTimeEqual("abcd" as void*, "abcd" as void*, 4), ssh.ConstantTimeEqual("abcd" as void*, "abce" as void*, 4)

    mut b2 := ssh.NewBuf(16)
    ssh.BufPutStringBuf(b2, b)
    ssh.BufPutMpintBuf(b2, b)
    ssh.BufPutBuf(b2, b)
    mut r2 := ssh.NewReader(b2.p, b2.len)
    view := ssh.RGetStringView(r2)
    println view.len == b.len
    mut copied := ssh.RGetStringCopy(ssh.ReaderFromBuf(b2))
    mut number := ssh.RGetMpintCopy(r2)
    println copied.len, number.len, ssh.RRemaining(r2)
    ssh.WipeBuf(b)
    ssh.FreeBuf(b)
    ssh.FreeBuf(b2)
    ssh.FreeBuf(copied)
    ssh.FreeBuf(number)
end
Output59 20 7 9 true ssh-ed25519,rsa-sha2-256 true abc 6 1 0 aes256-ctr true false true 59 59 59

FreeBuf

func FreeBuf(b &: Buf)
Frees the buffer.

The example for this item is shown with the ones above: ssh-Wire.salam

WipeBuf

func WipeBuf(b &: Buf)
Zeroes the contents of the buffer.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutByte

func BufPutByte(b &: Buf, v: int)
Adds one byte.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutBytes

func BufPutBytes(b &: Buf, p: void*, n: int)
Adds bytes from memory.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutBuf

func BufPutBuf(b &: Buf, src: Buf)
Adds the contents of another buffer.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutZeros

func BufPutZeros(b &: Buf, n: int)
Adds n zero bytes.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutUint32

func BufPutUint32(b &: Buf, v: u32)
A 32 bit big-endian number.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutUint64

func BufPutUint64(b &: Buf, v: u64)
A 64 bit big-endian number.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutBool

func BufPutBool(b &: Buf, v: bool)
A boolean as one byte.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutString

func BufPutString(b &: Buf, p: void*, n: int)
An SSH string: a 4 byte length and then the bytes.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutStringBuf

func BufPutStringBuf(b &: Buf, src: Buf)
Adds a buffer as an SSH string.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutStringStr

func BufPutStringStr(b &: Buf, s: str)
Adds text as an SSH string.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutMpintBytes

func BufPutMpintBytes(b &: Buf, p: void*, n: int)
A big number, mpint, from big-endian bytes.

The example for this item is shown with the ones above: ssh-Wire.salam

BufPutMpintBuf

func BufPutMpintBuf(b &: Buf, src: Buf)
An mpint from a buffer.

The example for this item is shown with the ones above: ssh-Wire.salam

NewReader

func NewReader(p: void*, n: int): Reader
A reader over memory.

The example for this item is shown with the ones above: ssh-Wire.salam

ReaderFromBuf

func ReaderFromBuf(b: Buf): Reader
A reader over a buffer.

The example for this item is shown with the ones above: ssh-Wire.salam

RRemaining

func RRemaining(r: Reader): int
The bytes not yet read.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetByte

func RGetByte(r &: Reader): int
Reads one byte.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetBool

func RGetBool(r &: Reader): bool
Reads a boolean.

The example for this item is shown with the ones above: ssh-Wire.salam

RSkip

func RSkip(r &: Reader, n: int)
Skips n bytes.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetUint32

func RGetUint32(r &: Reader): u32
Reads a 32 bit number.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetUint64

func RGetUint64(r &: Reader): u64
Reads a 64 bit number.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetStringView

func RGetStringView(r &: Reader): Reader
An SSH string without copying, as a reader over the same memory.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetStringCopy

func RGetStringCopy(r &: Reader): Buf
Copies an SSH string into a new buffer.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetStringAsStr

func RGetStringAsStr(r &: Reader): str
An SSH string as text.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetMpintView

func RGetMpintView(r &: Reader): Reader
An mpint without copying and without the leading zero.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetMpintCopy

func RGetMpintCopy(r &: Reader): Buf
Copies an mpint.

The example for this item is shown with the ones above: ssh-Wire.salam

RGetNameList

func RGetNameList(r &: Reader): str
A list of names, such as algorithms, separated by commas.

The example for this item is shown with the ones above: ssh-Wire.salam

NameListContains

func NameListContains(list: str, name: str): bool
The name list holds this name.

The example for this item is shown with the ones above: ssh-Wire.salam

NegotiateFirstMatch

func NegotiateFirstMatch(mine: str, theirs: str): str
The first name in your own list that the other side also has; the algorithm negotiation rule of SSH.

The example for this item is shown with the ones above: ssh-Wire.salam

ConstantTimeEqual

func ConstantTimeEqual(a: void*, b: void*, n: int): bool
Compares two pieces of memory in constant time.

The example for this item is shown with the ones above: ssh-Wire.salam

SftpOpen

func SftpOpen(client &: Client): Sftp
Opens the SFTP subsystem over the connection.

The example for this item is shown with the ones above: ssh-Sftp.salam

SftpClose

func SftpClose(client &: Client, sftp &: Sftp)
Closes SFTP.

The example for this item is shown with the ones above: ssh-Sftp.salam

Upload

func Upload(client &: Client, sftp &: Sftp, local_path: str, remote_path: str): bool
Uploads a local file.

The example for this item is shown with the ones above: ssh-Sftp.salam

Download

func Download(client &: Client, sftp &: Sftp, remote_path: str, local_path: str): bool
Downloads a file from the server.

The example for this item is shown with the ones above: ssh-Sftp.salam

Mkdir

func Mkdir(client &: Client, sftp &: Sftp, path: str): bool
Makes a directory.

The example for this item is shown with the ones above: ssh-Sftp.salam

Remove

func Remove(client &: Client, sftp &: Sftp, path: str): bool
Deletes a file.

The example for this item is shown with the ones above: ssh-Sftp.salam

Rmdir

func Rmdir(client &: Client, sftp &: Sftp, path: str): bool
Deletes an empty directory.

The example for this item is shown with the ones above: ssh-Sftp.salam

Rename

func Rename(client &: Client, sftp &: Sftp, old_path: str, new_path: str): bool
Renames or moves.

The example for this item is shown with the ones above: ssh-Sftp.salam

Stat

func Stat(client &: Client, sftp &: Sftp, path: str): SftpFileInfo
The information about a file; it follows links.

The example for this item is shown with the ones above: ssh-Sftp.salam

Exists

func Exists(client &: Client, sftp &: Sftp, path: str): bool
The file or directory is there.

The example for this item is shown with the ones above: ssh-Sftp.salam

ListDir

func ListDir(client &: Client, sftp &: Sftp, path: str): Vector<SftpFileInfo>
The contents of a directory, without . and ...

The example for this item is shown with the ones above: ssh-Sftp.salam

MkdirAll

func MkdirAll(client &: Client, sftp &: Sftp, path: str): bool
Makes the directory and every directory above it.

The example for this item is shown with the ones above: ssh-Sftp.salam

RemoveAll

func RemoveAll(client &: Client, sftp &: Sftp, path: str): bool
Deletes the directory and everything in it.

The example for this item is shown with the ones above: ssh-Sftp.salam

DownloadDir

func DownloadDir(client &: Client, sftp &: Sftp, remote_path: str, local_path: str): bool
Downloads a directory with everything in it.

The example for this item is shown with the ones above: ssh-Sftp.salam

UploadDir

func UploadDir(client &: Client, sftp &: Sftp, local_path: str, remote_path: str): bool
Uploads a local directory with everything in it.

The example for this item is shown with the ones above: ssh-Sftp.salam

Lstat

func Lstat(client &: Client, sftp &: Sftp, path: str): SftpFileInfo
The information about the link itself, without following it.

The example for this item is shown with the ones above: ssh-Sftp.salam

func IsLink(client &: Client, sftp &: Sftp, path: str): bool
It is a symbolic link.

The example for this item is shown with the ones above: ssh-Sftp.salam

SelfTest

func SelfTest(): int
Runs the internal tests of the package; returns the number of failures.

The example for this item is shown with the ones above: ssh-Exec.salam

Dial

func Dial(cfg: Config): Client
Connects to the server and checks the host key, without logging in.

The example for this item is shown with the ones above: ssh-Exec.salam

Connect

func Connect(cfg: Config): Client
Connects and logs in.

The example for this item is shown with the ones above: ssh-Exec.salam

Ok

func Ok(client: Client): bool
The connection and login succeeded.

The example for this item is shown with the ones above: ssh-Exec.salam

Error

func Error(client: Client): str
The error message.

The example for this item is shown with the ones above: ssh-Exec.salam

HostKeyFingerprint

func HostKeyFingerprint(client: Client): str
The SHA-256 fingerprint of the host key, the one ssh shows.

The example for this item is shown with the ones above: ssh-Exec.salam

Close

func Close(client &: Client)
Closes the connection.

The example for this item is shown with the ones above: ssh-Exec.salam

Reconnect

func Reconnect(client &: Client): bool
Connects again with the same configuration.

The example for this item is shown with the ones above: ssh-Exec.salam

RunCommand

func RunCommand(client &: Client, cmd: str): ExecResult
The same as Exec.

The example for this item is shown with the ones above: ssh-Exec.salam