Re: IdFTPServer don`t work correct?

Giganews Newsgroups
Subject: Re: IdFTPServer don`t work correct?
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Thu, 3 Mar 2005

"Dimm" <Di…@aport.ru> wrote in message
news:23EA8E44E6F883EC293Di…@aport.ru...

> TList *FTPThreadList = FTPServer->Threads->LockList();
> FTPServer->Threads->UnlockList();

You should not be unocking the list yet.  You need to keep it locked while
you are accessing the threads.

>  if(lstrcmpi("10.1.1.1", ((TIdPeerThread
*)FTPThreadList->Items[i]->Connection->Socket->Binding->PeerIP.c_str()) ==
0)

Use the following instead:

    if( ((TIdPeerThread
*)FTPThreadList->Items[i])->Connection->Socket->Binding->PeerIP ==
"10.1.1.1" )

> // This strings terminate with window Access Violation
>    ((TIdPeerThread
*)FTPThreadList->Items[i])->Connection->DisconnectSocket();
>    ((TIdPeerThread
*)FTPThreadList->Items[i])->Connection->WriteBuffer(szCodeTerminate);
>    }

There are several problems with that code:

1) you did not keep the TThreadList locked.  When you disconnect the socket,
its thread disappears from the server's Threads list and is freed, so you
are most likely accessing invalid pointers.  That would account for the AV.

2) you are disconnecting the wrong socket to begin with.  FTP uses multiple
connections per client - one connection for exchanging commands/responses,
and separate connections for the actual data transfers.  You are
disconnecting the socket used for exchanging commands/responses, not socket
used for data transfers.  Data transfers do not appear in the Threads list
at all.  You need to cast the TIdPeerThread pointer to a TIdFTPServerThread
and then call the TIdFTPServerThread::KillDataChannel() method.

3) you are trying to write data to the socket you just disconnected.  Even
then, you are not writing valid FTP response data anyway.  At the very
least, you did not include a CRLF at the end of the string.

> How i answer to the FTP client about that what the specified file or
folder does not exist?

Simply throw an exception in the appropriate event handler (OnGetFile,
OnStoreFile, OnChangeDirectory).  TIdFTPServer sends back the Exception's
message in a properly-formatted FTP response.

> > > 5. Why the component hangs at copying a plenty of files and folders?
> >
> > Again, you need to provide much more details.
>
> It is shown at copying a many files and folder from/to server.What you can
advise?

I do not understand what you are asking for.

Gambit

Replies

In response to

IdFTPServer don`t work correct? posted by Dimm on Thu, 3 Mar 2005