unit SFTPUnit;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls, tgputtylib, tgputtysftp,
Vcl.Grids;
type
TForm1 =
class(TForm)
Button1: TButton;
InfoLB: TListBox;
RemoteFilesSG: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
TestSFTP :TTGPuttySFTP;
function onVerifyHostKey(
const host:PAnsiChar;
const port:Integer;
const fingerprint:PAnsiChar;
const verificationstatus:Integer;
var storehostkey:Boolean): Boolean;
procedure Verbinden;
procedure Trennen;
procedure DatenAbruf;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
Username = '
name';
Passwort = '
passwort';
Host = '
ssh.strato.de';
Port = 22;
function TForm1.onVerifyHostKey(
const host: PAnsiChar;
const port: Integer;
const fingerprint: PAnsiChar;
const verificationstatus: Integer;
var storehostkey: Boolean): Boolean;
(* Verhindert einen Abbruch bei Connect *)
begin
storeHostKey := true;
end;
procedure TForm1.Verbinden;
begin
TestSFTP.HostName := Host;
TestSFTP.UserName := UserName;
TestSFTP.Password := Passwort;
TestSFTP.Port := Port;
TestSFTP.OnVerifyHostKey := onVerifyHostkey;
try
TestSFTP.Connect;
except
on E:
Exception do WriteLn('
EXCEPTION: ',E.
Message);
end;
if TestSFTP.Connected
then Form1.InfoLB.Items.Insert(0, '
Angeblich verbunden :-)');
end;
procedure TForm1.Trennen;
begin
TestSFTP.Disconnect;
end;
procedure TForm1.DatenAbruf;
begin
RemoteFilesSG.RowCount:=1;
RemoteFilesSG.ColCount:=3;
RemoteFilesSG.ColWidths[0]:=480;
RemoteFilesSG.ColWidths[1]:=300;
RemoteFilesSG.ColWidths[2]:=150;
RemoteFilesSG.Cells[0,0]:='
Name';
RemoteFilesSG.Cells[1,0]:='
Timestamp';
RemoteFilesSG.Cells[2,0]:='
Size';
TestSFTP.ListDir('
');
if RemoteFilesSG.RowCount>1
then RemoteFilesSG.FixedRows:=1;
RemoteFilesSG.FixedCols:=0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TestSFTP := TTGPuttySFTP.Create(true);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption = '
Start'
then
begin
Verbinden;
Button1.Caption := '
Ende';
end else
begin
Trennen;
Application.Terminate;
end;
end;
end.