Hello,
How can I check if a file exists on a ftp server?
I need to check if a file exists on server because I don't want to
overwrite it.
Thank you!

Using indy ftp I managed to do this using the following function.
How can I modify this to the ics ftp coding style?

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 thenbegin
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)));endelsebegin
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;

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
This
email has been sent from a virus-free computer protected by Avast.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to