FtpServer closes connection if file does't exist

Giganews Newsgroups
Subject: FtpServer closes connection if file does't exist
Posted by:  Tomasz B (t.berg.REMO…@slican.pl)
Date: Thu, 02 Oct 2008

Next part of my indy idFTPserver saga and passive mode ;)

The problem which I focus this time is to make IdFtpServer working in
the same way as the other FTP servers do.

Servers which I use (Filezilla/vsFTPd) arespond with RFC 550 code when
are asked to operate on not existed file (ie.
OnRetrieveFile/OnGetFileSize) and despite of operation failed keep an
opened connection to a ftp client.

My code (shown below) should do the same but it also close the
connection to the ftp client if required file doesn't exist and a
passive mode is used (an EIdSocketError exception is thrown in client).

void __fastcall CServer::IdFTPServerRetrieveFile(
  TIdFTPServerContext *aSender, const AnsiString aFileName,
  TStream* &vStream)
  bool fileExists = true;
  if (!FileExists(convertPath2Win( aFileName, aSender->HomeDir ))) {
    vStream = NULL;
    fileExists = false;
  else {
    vStream = new TFileStream(convertPath2Win( aFileName,
aSender->HomeDir ) , fmOpenRead | fmShareDenyWrite ) ;
    if (!fileExists) {
    throw EIdReplyRFCError(550, "Failed to open file.");

What should I do to keep the connection opened ?

Best regards
Tomasz Berg