I am trying to find out how to connect to the sftp server.
I can connect the ScSSHClient, but when I call the ScSFTPClient.initialize the programm freezes. Any suggestions what to do?
Thanks,
Rob Nowee
See Code Below
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
OldCursor: TCursor;
Handle: TScSFTPFileHandle;
i: Integer;
Path, Selectedname: String;
ScFileStorage1: TScFileStorage;
ScSFTPClient1: TScSFTPClient;
ScSSHClient1: TScSSHClient;
Key: TScKey;
begin
ScFileStorage1:= TScFileStorage.Create(self);
ScSFTPClient1:= TScSFTPClient.Create(self);
ScSSHClient1:= TScSSHClient.Create(self);
ScFileStorage1.Path :='d:\indir';
ScSSHClient1.KeyStorage := ScFileStorage1;
ScSSHClient1.HostName := 'sftp.edi-p.staples.eu';
ScSSHClient1.User := username;
ScSSHClient1.Password := Password;
ScSSHClient1.Port := 22;
ScSFTPClient1.SSHClient := ScSSHClient1;
if not (FileExists('d:\indir\Key1.key')) then
begin
Key := TScKey.Create(ScFileStorage1.Keys);
Key.KeyName := 'key1';
Key.ImportFrom('d:\indir\sftp.edi-p.staples.eu.key');
end;
ScSSHClient1.HostKeyName := 'Key1';
ScSSHClient1.Connect;
ScSFTPClient1.Timeout:=300;
ScSFTPClient1.Initialize;
ScSFTPClient1.DownloadFile('*.*','D:\Indir\',True);
OldCursor := Screen.Cursor;
try
Screen.Cursor := crHourGlass;
Path := '/';
Path := Trim(Path);
Handle := ScSFTPClient1.OpenDirectory(Path);
try
FileView.Items.Clear;
repeat
ScSFTPClient1.ReadDirectory(Handle);
until ScSFTPClient1.EOF;
finally
ScSFTPClient1.CloseHandle(Handle);
end;
lbRootDir.Text := ScSFTPClient1.RetrieveAbsolutePath(Path);
if SelectedName <> '' then begin
for i := 0 to FileView.Items.Count - 1 do
if LowerCase(FileView.Items[i].Text) = LowerCase(SelectedName) then begin
FileView.Selected := FileView.Items[i];
Exit;
end;
end;
finally
Screen.Cursor := OldCursor;
end;
end;