Inhaltsverzeichnis

std.net.ssh

SSH-2 (Secure Shell, RFC 4253) ist das Standardprotokoll für verschlüsselten Remote-Zugriff auf Server. Die Unit basiert auf libssh2 und unterstützt Verbindungsaufbau, passwort- und schlüsselbasierte Authentifizierung, Remote-Kommandoausführung (SSHExec/SSHExecOutput) und interaktive Shell-Sitzungen.

Einsatzbereiche sind Server-Automatisierung, Deployment-Skripte, Konfigurationsmanagement, Monitoring-Agenten, Backup-Tools und jede Anwendung, die Befehle sicher auf entfernten Linux-Systemen ausführen muss.

import std.net.ssh;

var sess: SSHSession := SSHSessionNew();
SSHConnect(sess, "192.168.1.10", 22);
SSHAuth(sess, "admin", "secret");

var output: pchar := SSHExecOutput(sess, "uptime");
PrintStr(output);
SSHDisconnect(sess);


Imports


Externe Funktionen

Signatur
libssh2_init(flags: int64): int64
libssh2_exit()
libssh2_session_init_ex(alloc: int64, free: int64, realloc: int64, abstract_ptr: int64): int64
libssh2_session_free(session: int64): int64
libssh2_session_handshake(session: int64, sock: int64): int64
libssh2_session_disconnect_ex(session: int64, reason: int64, description: int64, lang: int64): int64
libssh2_session_set_timeout(session: int64, timeout: int64)
libssh2_userauth_password_ex(session: int64, username: int64, username_len: int64, password: int64, password_len: int64, passwd_change_cb: int64): int64
libssh2_channel_open_ex(session: int64, channel_type: int64, channel_type_len: int64, window_size: int64, packet_size: int64, message: int64, message_len: int64): int64
libssh2_channel_process_startup(channel: int64, request: int64, request_len: int64, message: int64, message_len: int64): int64
libssh2_channel_read_ex(channel: int64, stream_id: int64, buf: int64, buflen: int64): int64
libssh2_channel_write_ex(channel: int64, stream_id: int64, buf: int64, buflen: int64): int64
libssh2_channel_send_eof(channel: int64): int64
libssh2_channel_eof(channel: int64): int64
libssh2_channel_close(channel: int64): int64
libssh2_channel_free(channel: int64): int64
libssh2_channel_wait_closed(channel: int64): int64
libssh2_session_last_error(session: int64, errmsg: int64, errmsg_len: int64, want_buf: int64): int64

Konstanten

Name Typ Wert Sichtbarkeit
SSH_PORT int64 22 pub
LIBSSH2_INIT_NOCRYPTO int64 0 pub
LIBSSH2_INIT_NOCRYPTO_DEPRECATED int64 1 pub

Typen

SSHSession (struct)

Feld Typ

SSHChannel (struct)

Feld Typ

Funktionen

Signatur Sichtbarkeit Beschreibung
SSHStrLen(s: int64): int64 pub Länge eines C-Strings berechnen
SSHGlobalInit(): int64 pub libssh2 global initialisieren
SSHGlobalCleanup() pub libssh2 global deinitialisieren
SSHSessionNew(): SSHSession pub Neue SSH-Session erstellen
SSHConnect(session: SSHSession, host: int64, port: int64): int64 pub TCP-Verbindung und Handshake aufbauen
SSHAuth(session: SSHSession, username: int64, password: int64): int64 pub Passwortbasierte Authentifizierung durchführen
SSHOpenShell(session: SSHSession): SSHChannel pub Interaktive Shell-Sitzung öffnen
SSHExec(session: SSHSession, command: int64): SSHChannel pub Remote-Befehl ausführen, Kanal zurückgeben
SSHRead(channel: SSHChannel, buf: int64, bufsize: int64): int64 pub Daten aus SSH-Kanal lesen
SSHWrite(channel: SSHChannel, buf: int64, bufsize: int64): int64 pub Daten in SSH-Kanal schreiben
SSHEof(channel: SSHChannel): int64 pub Prüfen ob Kanal-EOF erreicht
SSHSendEof(channel: SSHChannel): int64 pub EOF-Signal an Kanal senden
SSHClose(channel: SSHChannel) pub SSH-Kanal schließen und freigeben
SSHDisconnect(session: SSHSession) pub SSH-Verbindung ordentlich trennen
SSHFree(session: SSHSession) pub Session-Speicher freigeben
SSHExecOutput(session: SSHSession, command: int64, maxOutput: int64): int64 pub Befehl ausführen, Ausgabe als String