Board index » delphi » Best way to see file existence with TIdFtp

Best way to see file existence with TIdFtp


2004-06-23 05:41:14 AM
delphi96
Hello.
?What do you think is the best way to see at file existence before download
it ?
Now I'am using this two ways :
a)
try
IdFtp.Put(Stream, Flag);
except
// does'nt exists
end;
b)
try
IdFtp.List(Files, 'MyFile.txt', False);
except
// does'nt exists
end;
if Files.Count = 1 then begin
// File exist
end;
In both approachs, I must use a try...except to protect code from exception
due to file not existence. But I ca'nt know if exception was due to file not
existence or any other error.
?What's the best way to do it ?
Thank you.
 
 

Re:Best way to see file existence with TIdFtp

"Marc Guillot" <XXXX@XXXXX.COM>writes
Quote
?What do you think is the best way to see at
file existence before download it ?
Perform a directory listing first and then see if the file is listed.
Alternatively, you can use Size(), but not all servers support the 'SIZE'
command.
Quote
In both approachs, I must use a try...except to protect
code from exception due to file not existence. But I
ca'nt know if exception was due to file not existence or
any other error.
Yes, you can. If the exception is an EIdProtocolReplyError, then you can
look at its ReplyErrorCode property to find out why it failed.
Gambit
 

Re:Best way to see file existence with TIdFtp

O.k. I will do it.
Thank you.
Quote
Yes, you can. If the exception is an EIdProtocolReplyError, then you can
look at its ReplyErrorCode property to find out why it failed.