var
SSH: TsgcSSHClient;
SFTP: TsgcSFTPClient;
begin
SSH := TsgcSSHClient.Create(nil);
SSH.Host := 'build01.example.com';
SSH.Port := 22;
SSH.Authentication.Username := 'deploy';
SSH.Authentication.PrivateKeyFile := 'C:\keys\id_ed25519.pem';
SSH.OnSSHHostKey := SSHHostKey;
SSH.Connect;
Memo1.Text := SSH.Execute('uname -a');
SSH.Disconnect;
SFTP := TsgcSFTPClient.Create(nil);
SFTP.Host := 'files.example.com';
SFTP.Authentication.Username := 'partner';
SFTP.Authentication.Password := 'secret';
SFTP.Connect;
SFTP.Put('C:\export\invoices.zip', '/upload/invoices.zip');
SFTP.Disconnect;
end;
begin
SFTPServer := TsgcSFTPServer.Create(nil);
SFTPServer.RootFolder := 'D:\sftp';
SFTPServer.SFTP := True;
SFTPServer.SCP := True;
SFTPServer.OnSFTPUserRoot := SFTPUserRoot;
SSHServer := TsgcSSHServer.Create(nil);
SSHServer.Port := 2222;
SSHServer.HostKeyFiles.Text := 'hostkey_ed25519.pem';
SSHServer.OnSSHAuthPassword := SSHAuthPassword;
SSHServer.SFTPServer := SFTPServer;
SSHServer.Active := True;
end;
procedure TForm1.SSHAuthPassword(Sender: TObject;
aConnection: TsgcSSHServerConnection; const aUsername, aPassword: string;
var aAccept: Boolean);
begin
aAccept := CheckUser(aUsername, aPassword);
end;
procedure TForm1.SFTPUserRoot(Sender: TObject; const aUsername: string;
var aRootFolder: string);
begin
aRootFolder := 'D:\sftp\' + aUsername;
end;