I have been using another sFTP component for a few years, which I have to replace because downloading a lot of files was a problem for me.
I chose Devart, first of all I find it very difficult to use, when it comes to downloading several files in the same directory... Forced to fill out a list and then go through it!! It's a consumer of neurons...
I encounter a difficulty that I cannot solve. I can't use it in a Windows service! That's where I'm at..
Code: Select all
Function TServiceCde.DownLoadCSV:Integer;
Var
SSH : TScSSHClient;
SFTPClient : TScSFTPClient;
FileStorage : TScFileStorage;
Handle : TScSFTPFileHandle;
RootDir : string;
begin
SSH := TScSSHClient.Create(nil);
FileStorage := TScFileStorage(nil);
Try
Try
SSH.KeyStorage := FileStorage;
SSH.HostName := FTPHost;
SSH.Port := FTPPort;
SSH.User := FTPLogin;
SSH.Authentication := atPassword;
SSH.Password := FTPPassword;
SSH.HostKeyAlgorithms.AsString :='ssh-rsa,ssh-dss';
SSH.OnServerKeyValidate := ScSSHClientServerKeyValidate;
Log('1: configuration connexion SSH');
SSH.Connect;
SFTPClient := TScSFTPClient.Create(nil);
Try
Try
SFTPClient.SSHClient := SSH;
SFTPClient.Initialize;
Log('3: SFTP initié');
if FTPRepertoire1 <> '' then
begin
RootDir := SFTPClient.RetrieveAbsolutePath(Trim(FTPRepertoire1));
Handle := SFTPClient.OpenDirectory(RootDir);
if FTPRepertoire2 <> '' then
begin
RootDir := SFTPClient.RetrieveAbsolutePath(Trim(FTPRepertoire2));
Handle := SFTPClient.OpenDirectory(RootDir);
if FTPRepertoire3 <> '' then
begin
RootDir := SFTPClient.RetrieveAbsolutePath(Trim(FTPRepertoire3));
Handle := SFTPClient.OpenDirectory(RootDir);
if FTPRepertoire4 <> '' then
begin
RootDir := SFTPClient.RetrieveAbsolutePath(Trim(FTPRepertoire4));
Handle := SFTPClient.OpenDirectory(RootDir);
end;
end;
end;
end;
Log('4: Chemin daccès attribué');
iCompteurFtpDevart := 0; SetLength(FileDownLoadsFtp,iCompteurFtpDevart);
While not SFTPClient.EOF(Handle) do
SFTPClient.ReadDirectory(Handle);
// just for view
for i := Low(FileDownLoadsFtp) to High(FileDownLoadsFtp) do
Log(' file : ' + FileDownLoadsFtp[i].NameFile + ' - taille : ' + IntToStr(FileDownLoadsFtp[i].TailleFile));
Except
ON E:Exception do
begin
Log(' *** Erreur : sFTPClient ');
Log(' *** Erreur : Message '+ E.Message);
end;
End;
Finally
SFTPClient.Disconnect;
if Assigned(SFTPClient) then FreeAndNil(SFTPClient);
end;
Except
ON E:Exception do
begin
Log(' *** Erreur : Connexion sur le serveur '+FTPHost);
Log(' *** Erreur : Message '+ E.Message);
end;
End;
Finally
SSH.Disconnect;
if Assigned(SSH) then FreeAndNil(SSH);
End;
end;
Code: Select all
procedure TServiceCde.ScSSHClientServerKeyValidate(Sender: TObject;
NewServerKey: TScKey; var Accept: Boolean);
begin
Accept:=True;
end;
Surely I must be using TscFileStorage incorrectly?
*** Erreur : Connexion sur le serveur xx.xxx.xxx.xxx
*** Erreur : Message Storage is no set
Aucun fichier à récupérer.
Thank you for your help