sgcSSH: Post-Quantum SSH, SFTP and SCP for Delphi and .NET

· Components
sgcSSH: Post-Quantum SSH, SFTP and SCP for Delphi and .NET
New product · sgcSSH

SSH, SFTP and SCP for Delphi and .NET.
Post-quantum by default.

Three clients and two servers that put SSH inside your own applications. The hybrid key exchange mlkem768x25519-sha256 is offered first on both sides, and the cryptography runs as native code.

  • ML-KEM-768 + X25519
  • SFTP v3
  • SCP
  • Ed25519
  • AES-GCM
The sgcSSH demos side by side: the SSH client running a command and an interactive shell, the SFTP client browsing a remote folder, the SFTP server serving a root folder, and a terminal showing the key exchange mlkem768x25519-sha256
5components
16SFTP requests in flight
~1 sper 100 MB on a LAN
0OpenSSL DLLs with native crypto

SSH is the standard way to manage servers and to exchange files securely. sgcSSH brings it to your Delphi, C++Builder and .NET applications as ordinary components, on the client side and on the server side.

With sgcSSH you run a command on a Linux server and get its output as a string, open an interactive shell, forward a port, upload a folder over SFTP or SCP, or turn your own application into an SSH and SFTP server with a private folder for every user. Client and server both offer the hybrid post-quantum key exchange first, the one the latest SSH releases use by default.

sgcSSH at a glance: the clients, the servers and the post-quantum key exchange. Also on YouTube.

Three Clients, Two Servers

Each one is a non-visual component on the SGC SSH palette page. You drop it on a form or create it in code, set the host and the credentials, wire the events, then connect or start listening. The .NET classes carry the same names.

SSH clientTsgcSSHClientCommands, interactive shells with a pty, port forwarding and rekey.
SFTP clientTsgcSFTPClientSFTP v3 file transfers with 16 requests in flight.
SCP clientTsgcSCPClientFiles and whole folders with scp, keeping the file times.
SSH serverTsgcSSHServerPassword and public key sign-in, exec, shell and subsystems.
SFTP serverTsgcSFTPServerSFTP v3 and SCP from a root folder, with a jail per user.

Post-Quantum Key Exchange, On by Default

Traffic encrypted today can be attacked tomorrow. An attacker records the encrypted session now and decrypts it later, once a large enough quantum computer exists. This is called harvest now, decrypt later, and it matters for anything that has to stay private for years: credentials, contracts, customer files.

sgcSSH answers it with the hybrid key exchange mlkem768x25519-sha256. It combines ML-KEM-768 (FIPS 203), a post-quantum algorithm, with the classic X25519, so the session keys stay secret as long as one of the two is not broken. It is the default of the latest SSH releases.

This is a standard ssh command line client connecting to the SSH server demo. The hybrid exchange is negotiated with default settings on both sides:

ssh -v against TsgcSSHServer
$ ssh -v -p 2290 deploy@127.0.0.1 "echo hello"
debug1: Remote protocol version 2.0, remote software version sgcSSH
debug1: kex: algorithm: mlkem768x25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
Authenticated to 127.0.0.1 ([127.0.0.1]:2290) using "password".
hello

Native Cryptography, No DLL to Deploy

In Delphi, the CryptoLibrary property chooses where the classic algorithms (ECDH, Diffie-Hellman, AES, HMAC and the host key signatures) are computed:

The hybrid ML-KEM-768 and X25519 exchange is native code of the library with both options. The .NET components are fully managed code with no OpenSSL at all, and on .NET 8 and later AES-GCM is hardware accelerated.

Uploading a file over SFTP with the post-quantum exchange and the native cryptography takes a handful of lines:

uses
  sgcSSH_Crypto, sgcSSH_Client;

procedure TForm1.UploadInvoices;
var
  SFTP: TsgcSFTPClient;
begin
  SFTP := TsgcSFTPClient.Create(nil);
  try
    SFTP.Host := 'files.example.com';
    SFTP.Authentication.Username := 'partner';
    SFTP.Authentication.Password := 'secret';
    SFTP.PostQuantumKex := True;      // the default: mlkem768x25519-sha256 first
    SFTP.CryptoLibrary := sshcNative; // sgcCrypto units, no OpenSSL DLL
    SFTP.Connect;
    SFTP.Put('C:\export\invoices.zip', '/upload/invoices.zip');
    Memo1.Lines.Add('Uploaded ' +
      IntToStr(SFTP.FileSize('/upload/invoices.zip')) + ' bytes');
    SFTP.Disconnect;
  finally
    SFTP.Free;
  end;
end;

The SSH Client: Commands, Shells and Tunnels

TsgcSSHClient signs in with a password or a private key, and OnSSHHostKey hands you the host key type and its fingerprint so you can check it against your known hosts and reject an unknown or changed key.

The SSH client demo: connected with the post-quantum key exchange and the native crypto library, the output of a remote command, an interactive shell listing a folder, and the accepted Ed25519 host key in the log
The SSH client demo: a remote command, an interactive shell and the host key check.

Running a maintenance command with a private key and a host key check:

procedure TForm1.CheckDisk;
var
  SSH: TsgcSSHClient;
begin
  SSH := TsgcSSHClient.Create(nil);
  try
    SSH.Host := 'build01.example.com';
    SSH.Authentication.Username := 'deploy';
    SSH.Authentication.PrivateKeyFile := 'C:\keys\id_ed25519.pem';
    SSH.OnSSHHostKey := DoHostKey;
    SSH.Connect;
    Memo1.Text := SSH.Execute('df -h /var');
    SSH.Disconnect;
  finally
    SSH.Free;
  end;
end;

procedure TForm1.DoHostKey(Sender: TObject; const aHostKeyType,
  aFingerprint: string; var aAction: TIdSSHHostKeyVerification);
begin
  if aFingerprint <> FKnownFingerprint then
    aAction := sshHostKeyReject;
end;

SFTP and SCP: Fast File Transfers

TsgcSFTPClient speaks SFTP v3 over the same SSH connection, with one method per job: RealPath resolves the home folder, ListDirectory returns names, sizes and dates, Put and Get upload and download a file, and Rename, Delete, MakeDirectory and RemoveDirectory cover the rest of a file manager. OnSFTPProgress reports the bytes transferred for a progress bar.

Transfers are fast because the client does not wait for each block. It keeps 16 requests in flight, so a 100 MB file takes about one second on a local network.

The SFTP client demo: a remote folder listed with names, sizes, dates and folder flags, and the progress bar of a large download
The SFTP client demo browsing a remote folder while a large file downloads.

TsgcSCPClient copies files over SSH to any server that allows the scp command, with no separate file transfer service. Upload and Download copy one file, UploadFolder and DownloadFolder copy a whole folder tree, and PreserveTimes keeps the modification and access times on the other side.

The SCP client demo with buttons to upload and download a file or a whole folder, the preserve file times option and the progress of a transfer
The SCP client demo: single files or whole folders, with or without the file times.

Your Own SSH and SFTP Server

TsgcSSHServer listens on the port you choose and proves its identity with Ed25519, ECDSA or RSA host keys loaded from HostKeyFiles. GenerateHostKeyEd25519 creates one for you. OnSSHAuthPassword and OnSSHAuthPublicKey decide who gets in, the second one with the key type and its SHA256 fingerprint. OnSSHExec answers remote commands and OnSSHShell serves an interactive session. Any standard SSH client connects to it, including the ssh, sftp and scp command line tools.

Link a TsgcSFTPServer and the same server becomes a file server:

uses
  sgcSSH_Crypto, sgcSSH_Server, sgcSSH_SFTP_Server;

procedure TForm1.StartServer;
begin
  if not FileExists('hostkey_ed25519.pem') then
    TsgcSSHServer.GenerateHostKeyEd25519('hostkey_ed25519.pem');

  SFTP := TsgcSFTPServer.Create(Self);
  SFTP.RootFolder := 'D:\sftp';
  SFTP.OnSFTPUserRoot := DoUserRoot;
  SFTP.OnSFTPOperation := DoOperation;

  SSH := TsgcSSHServer.Create(Self);
  SSH.Port := 22;
  SSH.HostKeyFiles.Text := 'hostkey_ed25519.pem';
  SSH.CryptoLibrary := sshcNative;
  SSH.SFTPServer := SFTP;
  SSH.OnSSHAuthPassword := DoAuthPassword;
  SSH.Active := True;
end;

procedure TForm1.DoAuthPassword(Sender: TObject;
  aConnection: TsgcSSHServerConnection; const aUsername, aPassword: string;
  var aAccept: Boolean);
begin
  aAccept := CheckUser(aUsername, aPassword); // your own user store
end;

procedure TForm1.DoUserRoot(Sender: TObject; const aUsername: string;
  var aRootFolder: string);
begin
  aRootFolder := 'D:\sftp\' + aUsername; // every user in its own folder
  ForceDirectories(aRootFolder);
end;

procedure TForm1.DoOperation(Sender: TObject; const aUsername: string;
  aOperation: TsgcSFTPOperation; const aPath, aNewPath: string;
  var aAccept: Boolean);
begin
  if aOperation = sfoRemove then
    aAccept := False; // the client gets permission denied
end;

Here the standard sftp command line tool works with the SFTP server demo:

sftp against TsgcSFTPServer
$ sftp -P 2291 -b batch.txt deploy@127.0.0.1
sftp> cd reports
sftp> put Q4-summary-2026.xlsx
sftp> ls -l
-rw-r--r--   1 deploy   deploy     150000 Nov 13 10:28 Q3-summary-2026.xlsx
-rw-r--r--   1 deploy   deploy     204800 Nov 13 10:28 Q4-summary-2026.xlsx
sftp> cd ..
sftp> get catalog-2026.pdf
sftp> mkdir archive-2026

On the server side, every one of those operations went through OnSFTPOperation, where the demo logs it:

The SFTP server demo listening with the native crypto library, an Ed25519 host key and options for one subfolder per user, read only, SCP and denied deletes; the log shows the password sign-in, the listings, an open for write, an open for read and a new folder
The SFTP server demo logging the session above, one line per operation.

Security Details

Delphi, C++Builder and .NET

The same five components are available on every platform sgcSSH supports:

The .NET code reads the same way as the Delphi code:

using esegece.sgcWebSockets;

using (var sftp = new TsgcSFTPClient())
{
    sftp.Host = "files.example.com";
    sftp.Authentication.Username = "partner";
    sftp.Authentication.Password = "secret";
    sftp.Connect();
    sftp.Put(@"C:\export\invoices.zip", "/upload/invoices.zip");
    foreach (var item in sftp.ListDirectory("/upload"))
        Console.WriteLine($"{item.FileName}  {item.Size}");
    sftp.Disconnect();
}

Five demos in Demos\27.SSH show every component at work: 01.SSH_Client, 02.SFTP_Client, 03.SCP_Client, 04.SSH_Server and 05.SFTP_Server. The screenshots in this article come from them.

Editions

sgcSSH is included in sgcWebSockets Enterprise and sgcWebSockets All-Access. On .NET the components ship in the registered sgcWebSockets package, not in the free Community edition.

If you only need SSH and SFTP, the standalone sgcSSH pack is self-contained: it bundles the sgcWebSockets Core runtime together with the native cryptography the key exchange runs on, the sgcCustomIndy add-on that the Delphi components build on is always included in the order, and every license ships full source code.

Good to know. Check what your sgcWebSockets edition already covers before you buy. If you own Enterprise or All-Access, you already have all five components.

SSH Inside Your Application, Ready for What Comes Next

Download the trial, run the SSH server demo and connect to it with any SSH client. Then drop a TsgcSFTPClient on your own form.

Questions or feedback? Get in touch, you will get a reply from the people who wrote the code.