1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| unit Unit1;
interface
{$POINTERMATH ON}
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls, tgputtylib, tgputtysftp;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button_connect: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
edPort: TEdit;
edPassword: TEdit;
ListBox1: TListBox;
edUser: TEdit;
edHost: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button_connectClick(Sender: TObject);
function VerifyHostKeyCallback(const edHost: pansichar; const edPort: integer; const fingerprint: pansichar; const verificationstatus: integer; var storehostkey: boolean): boolean;
function Listingdir(const names: Pfxp_names): boolean;
private
SFTP: TTGPuttySFTP;
public
end;
var
Form1: TForm1;
racine: string;
implementation
{$R *.lfm}
{ TForm1 }
function TForm1.Listingdir(const names: Pfxp_names): boolean;
var
i: integer;
begin
for i := 0 to names.nnames - 1 do
begin
if (Utf8ToString(names.names[i].filename) = '.') or (Utf8ToString(names.names[i].filename) = '..') then continue;
if names.names[i].attrs.permissions and $F000 = $4000 then
begin
Listbox1.Items.insert(0, Utf8ToString(names.names[i].filename));
racine :=Utf8ToString(names.names[i].filename);
try
sftp.ListDir(racine);
except
continue
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
listbox1.Clear;
button1.Enabled := False;
try
// racine := sftp.HomeDir;
racine:='/';
sftp.changeDir(racine);
Listbox1.Items.insert(0, sftp.WorkDir);
sftp.ListDir(sftp.WorkDir);
finally
button1.Enabled := True;
end;
end;
function TForm1.VerifyHostKeyCallback(const edHost: pansichar; const edPort: integer; const fingerprint: pansichar; const verificationstatus: integer; var storehostkey: boolean): boolean;
begin
if verificationstatus = 0 then
begin
Result := True;
Exit;
end;
if MessageDlg('SSH', 'Please confirm the SSH host key fingerprint for ' + ansistring(edHost) + ', port ' + IntToStr(edPort) + ':' + sLineBreak + ansistring(fingerprint), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
Result := True;
storehostkey := Result;
end;
procedure TForm1.Button_connectClick(Sender: TObject);
begin
SFTP := TTGPuttySFTP.Create(True);
with SFTP do
begin
OnListing := Listingdir;
// OnMessage := MessageCallback;
// OnProgress := ProgressCallback;
//OnGetInput := GetInputCallback;
OnVerifyHostKey := VerifyHostKeyCallback;
HostName := edHost.Text;
UserName := edUser.Text;
Password := edPassword.Text;
Port := StrToInt(edPort.Text);
try
begin
Connect;
form1.Caption := 'connecté...';
end;
except
ShowMessage('erreur connection...');
end;
end;
end;
end. |
Partager