Indy FTP hangs (v. 8.0.22)

Giganews Newsgroups
Subject: Indy FTP hangs (v. 8.0.22)
Posted by:  Sandeep Jain (sja…@wherenet.com)
Date: Wed, 2 Nov 2005

I have a thread that watches for files in a FTP folder.

Indy FTP hangs after a few hours of reading files.

Any help would be most appreciated.

Indy version is old: 8.0.22.  Don't have the luxury of upgrading right now.

Here is the code.  I am pretty sure it is thread-safe etc.  The various logs suggest that
FTP->List method is where Indy hangs.

//---------------------------------------------------------------------------
void __fastcall WatcherThread::Execute(void)
{
    m_shutdown = false;

    while (!Terminated)
    {
        try
        {
        #ifndef SIMULATOR
            thelogman()->post(AnsiString("Get directory list for files matching pattern: ") +
                                m_dirWatcher->m_filePattern, "DirWatcherModule");
        #endif
            auto_ptr<TStrings>
                files(m_dirWatcher->m_ftp->DirectoryList(m_dirWatcher->m_filePattern)); ===> see DirectoryList method below.

            int err = FTP_OK;

            if (NULL != files.get())
            {
                for (int i=0; i < files->Count; i++)
                {
                    err = m_dirWatcher->m_ftp->Get(files->Strings[i]);

                    if (err != FTP_OK)
                    {
                    #ifndef SIMULATOR
                        thelogman()->post(AnsiString("Failed to retrieve file:") +
                                            files->Strings[i], "DirWatcherModule");
                    #endif
                    }

                    m_dirWatcher->m_fileFoundEvent->FileName = files->Strings[i];
                    m_dirWatcher->m_fileFoundEvent->FTPClient = m_dirWatcher->m_ftp;
                    m_dirWatcher->m_fileFoundEvent->FileContent = m_dirWatcher->m_ftp->FileContent();

                    if (m_dirWatcher->m_updateGUI)
                    {
                        Synchronize(Notify);
                    }
                    else
                    {
                        Notify();
                    }
                }
            }
        }
        catch (Exception& e)
        {
        #ifndef SIMULATOR
            thelogman()->post(AnsiString("Error occured in DirectoryWatcherThread.") + e.Message,
                                "DirWatcherModule");
        #endif
        }

        // For better responsiveness to thread shutdown.
        unsigned int timeLeft = m_dirWatcher->m_pollingInterval;
        unsigned int smallInterval = 1000;

        while(!Terminated && (timeLeft > 0))
        {
            if (timeLeft <  smallInterval)
            {
                smallInterval = timeLeft;
            }

            Sleep(smallInterval);
            timeLeft -= smallInterval;
        }
    }

    m_shutdown = true;
}

//---------------------------------------------------------------------------
TStrings*  WN_IdFTP::DirectoryList(AnsiString namePattern)
{
    TStringList* files = NULL;

    try
    {
        if (!m_ftp->Connected())
        {
            Disconnect();
            Connect();
        }
    }
    catch (Exception& e)
    {
        return NULL;
    }

    try
    {
        files = new TStringList;
        m_ftp->List(files, namePattern, false);
    }
    catch (Exception& e)
    {
        m_errCode = FTP_SOCKET_ERROR;
        Cancel();
        if (files)
        {
            delete files;
            files=NULL;
        }
    }

    return files;
}

Replies