ICS FTP - 用于检查ftp服务器上是否存在文件的功能

时间:2016-01-14 17:09:00

标签: delphi ftp internet-component-suite

有人知道如何使用Over byte ICS FTP检查ftp服务器上是否存在文件? 我是否必须列出所有文件,然后解析结果或有另一种方法来执行此操作? 谢谢。

我在Indy中使用以下代码。它有效。但在我的项目中,我想使用icsftp。如何为ics ftp更改此内容?

Function exista_fisier_pe_ftp_nonvizual(nume_fisier_cautat,ftp_host,ftp_port,ftp_username,ftp_password,ftp_directory:string;memo_loguri:Tmemo) :Boolean;
var l:TStringList;
    indyftp:Tidftp;
    Freq, StartCount, StopCount: Int64;
    TimingSeconds: real;

begin

dateseparator:='-';


{verific daca serverul ftp este ONLINE}
if not IS_FTP_ONLINE(ftp_username,ftp_password,ftp_host) then showmessage(datetimetostr(now)+' - serverul "'+ftp_host+'" este OFFLINE sau datele de conectare sunt incorecte!') else

begin

memo_loguri.Lines.Add(#13#10+'=====> START CAUTARE FISIER PE SERVER FTP <====='+#13#10);

{ START VERIFICARE VITEZA DE EXECUTIE }
QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(StartCount);



indyftp:=Tidftp.create(nil);
l:=tstringlist.create;

indyftp.Host:=ftp_host;
indyftp.Port:=strtoint(ftp_port);
indyftp.username:=ftp_username;
indyftp.password:=ftp_password;
indyftp.Passive:=true;
indyftp.Connect;

if indyftp.connected then
 begin
memo_loguri.Lines.Add(datetimetostr(now)+' - conectat cu succes la "'+indyftp.Host+'" portul '+inttostr(indyftp.Port));
memo_loguri.Lines.add(datetimetostr(now)+' - detectare sistem de operare server ftp: "'+indyftp.SystemDesc+'"');

indyftp.ChangeDir(ftp_directory);

memo_loguri.Lines.add(datetimetostr(now)+' - accesez directorul "'+ftp_directory+'"');

 try
{listez toate fisierele de pe ftp}
indyftp.List(l, '', false);

if l.IndexOf(nume_fisier_cautat) > -1 then
begin
result:=true;
memo_loguri.Lines.add(datetimetostr(now)+' - fisierul "'+nume_fisier_cautat+'" exista pe serverul ftp in directorul "'+indyftp.RetrieveCurrentDir+'" ,are dimensiunea de '+ FormatByteSize(indyFTP.Size(nume_fisier_cautat))+' si a fost incarcat pe server la data ' +datetostr(indyFTP.FileDate(nume_fisier_cautat)));
end
else
begin
result:=false;
memo_loguri.Lines.add(datetimetostr(now)+' - fisierul "'+nume_fisier_cautat+'" nu exista pe serverul ftp');
end;

finally
  l.free;
end;
  indyftp.free;


{ STOP VERIFICARE VITEZA DE EXECUTIE }
QueryPerformanceCounter(StopCount);
TimingSeconds := (StopCount - StartCount) / Freq;
{ Display timing: ... }
memo_loguri.Lines.Add(datetimetostr(now) + ' - comanda executata in: ' + formatfloat('0.00',TimingSeconds) + ' sec.'+#13#10);
memo_loguri.Lines.Add('=====> STOP CAUTARE FISIER PE SERVER FTP <====='+#13#10);

end;
end;
end;

0 个答案:

没有答案