IdFtp9->Connect() hangs

Giganews Newsgroups
Subject: IdFtp9->Connect() hangs
Posted by:  poojo hackma (poojo.com/mail)
Date: Thu, 8 Jun 2006

My Indy 9 TIdFtp component will hang in BCB6 if a connection can not be
found.  I have set a 2 second timeout, but this does not seem to effect the
Connect() method.

Am I doing something wrong?  Is there a better way of doing this?

Here's how my code is set up (with irrelevant code deleted):

  mFtp = new TIdFTP(NULL);
  mFtp->Host    = AnsiString(FTP_HOST1) + AnsiString(FTP_HOST2);
  mFtp->Username = AnsiString(FTP_USERNAME1) + AnsiString(FTP_USERNAME2);
  mFtp->Password = AnsiString(FTP_PASSWORD1) + AnsiString(FTP_PASSWORD2);
  mFtp->OnStatus = FtpStatus;
  mFtp->OnWork      = FtpWork;
  mFtp->OnWorkBegin = FtpWorkBegin;
  mFtp->OnWorkEnd  = FtpWorkEnd;
  mFtp->OnAfterGet  = FtpAfterGet;
  mFtp->ReadTimeout = 2000;          // timeout after 2 seconds
  try
  {    // includes a __finally for mFtp->Quit();
    try
    {  // includes a catch()
      mFtp->Connect(true);
      if (mFtp->Connected() == false)
      {
        MessageLog("Unable to connect to Update Server.");
      }
      else
      {
        // proceed to download my files and such.
      }
    }
    catch (const EIdSilentException &eId)
    {
      /*  A little about Indy Exceptions (copied from their help pages):
      "[The Exception] EIdConnClosedGracefully for servers is trapped and
handled.
      While EIdConnClosedGracefully can be an error it is often a "normal"
      condition. Because of this, it descends from EIdSilentException. You
can
      add EIdSilentException to your debugger options to tell the debugger
not to
      stop on these exceptions. The exception will still occur and your EXE
will
      still function the same, however the debugger just wont stop on them
for
      debugging."
      */
    }
    catch (const Exception &ex)
    {
      MessageLog(ex.Message.c_str());
    }
  }  // end of first try block
  __finally
  {
    try
    {
      mFtp->Abort(); // if a file transfer is in progress
      mFtp->Quit();  // closes the connection
      ::Sleep(1000); // control will still send a few messages back to mFtp
    }
    __finally
    {
      delete mFtp;
      mFtp = NULL;
    }
  }

Replies