[twsocket] FTPCli Multi-Threading!

Sandy Ganz sganz@bizrate.com
Fri, 9 Jun 2000 16:04:18 -0700


Experts -

I have a questions on creating a Multi-Threaded FTP Client that creates a
FtpCli component in  the threads execute method, and then gets set up to do
some FTP work.  What I am ultimately after is the ability to queue up a list
of FTP requests and fire them each off as their own thread (and own FTPCli).

I think I should run commands Async, so I can use a simple loop (In the
thread) to check status and bytes transferred. I tried this, but could not
get it to do any work when executed as an Async command.

Any Help of pointer on how to structure it better would be appreciated!
Great work on the components as well!!

Sandy Ganz

// C++Builder Code snip

void __fastcall TForm1::BMThread1Execute( TObject *Sender, TBMExecuteThread
*Thread, void *&Data)
{
    TFtpClient *LocalFtpPtr;

    LocalFtpPtr = new TFtpClient(NULL); // create in this threads context;

    // Tried this to both True and False, not sure if it matters in Async
Mode?

    LocalFtpPtr->MultiThreaded = true;

    LocalFtpPtr->HostName        = "localhost";
    LocalFtpPtr->Port            = "ftp";
    LocalFtpPtr->UserName        = "sandy";
    LocalFtpPtr->PassWord        = "sandy";
    LocalFtpPtr->HostDirName     = "D:\\temp";
    LocalFtpPtr->HostFileName    = "D:\\temp\\rpr30g.exe";
    LocalFtpPtr->LocalFileName   = "D:\\temp\\DeleteMe";
    LocalFtpPtr->Binary          = true;

    //  LocalFtpPtr->Receive(); (This works, file xfer happens)

    LocalFtpPtr->ReceiveAsync();    // does not appear to start up xfer

    // This is where I'm not really sure how to
    // check the status, I assume if the request
    // is not done then stay in the thread checking status.
    // It stays in this loop, and the
    // FTPServer never sees any connection

    while(!LocalFtpPtr->OnRequestDone)
    {
        ByteCount = LocalFtpPtr->ByteCount;    // ByteCount stays at zero

        if(Thread->Terminated )
            break;

        Thread->Synchronize(&SynchroEvent1);
    }

    delete LocalFtpPtr;    // Kill it dead, all done

}//End Execute of Thread
.
.
.