FTP in Thread

FTP in Thread

Post by sham » Sun, 02 Apr 2006 00:58:51



Hi,

I am using Delphi 7 and indy 9.

In my thread, if I set a break point on the put command, the file is ftp'd
correctly. When I run the app without the break point, I get a readtimeout
exception : Stack is :

ntdll.dll
C:\WINDOWS\System32\mswsock.dll
C:\WINDOWS\system32\WS2_32.dll
TIdStackWindows.WSSelect($39FD9E0,nil,nil,-2)
TIdSocketHandle.Readable(-2)
TIdIOHandlerSocket.Readable(-2)
TIdTCPConnection.ReadFromStack(True,-2,True)
TIdTCPConnection.ReadLn(#$A,-1,16384)
TIdTCPConnection.ReadLnWait(2147483647)
TIdTCPConnection.GetInternalResponse
TIdTCPConnection.GetResponse((...))
TIdTCPConnection.SendCmd('PORT 127,0,0,1,6,249',(...))
TIdFTP.SendPort($391D7E0)
TIdFTP.InternalPut('STOR testFile2.dat-FS=11',$39FCD60,True)
TIdFTP.Put($39FCD60,'testFile2.dat-FS=11',False)
TimFTPThread.SendEnvelope
TimFTPThread.ThreadExecute($3CBD9E0,False)
TimExecuteMethodThread.DoExecute
TimThread.Execute
C:\StarTeam\Inspiration Matters\Inspired Signage\Bin\ComposerWin32.exe
ThreadProc($3CBD9E0)
ThreadWrapper($38FEE30)
C:\StarTeam\Inspiration Matters\Inspired Signage\Bin\ComposerWin32.exe
C:\StarTeam\Inspiration Matters\Inspired Signage\Bin\ComposerWin32.exe
C:\WINDOWS\system32\kernel32.dll

The onstatus events give : Start Transferring and then the read time out
occurs.

If I remove the break point and put a sleep(100) in before the put command,
it seems to work.

Why is this happening?

Sham.
 
 
 

FTP in Thread

Post by sham » Sun, 02 Apr 2006 03:03:57

In fact, putting sleep(0) before the put command also works.

Why ???

 
 
 

FTP in Thread

Post by sham » Wed, 05 Apr 2006 21:36:54

Yes, I am creating a thread and doing the put inside it.

I have moved up the sleep to 50.

I am not using the latest dev snapshot. I am using version 9.0.14.
 
 
 

FTP in Thread

Post by Guille » Thu, 06 Apr 2006 23:13:15


keep in mind that the FTP protocol uses 2 connections to work: one for
the data, one for the communication of commands between client and
server. Maybe something in one or more of your threads is interfering
with it.

Thread-safety problems lead to often the weirdest problems and errors
you can imagine. That putting a sleep(0) kind of solves it should give
you a lead. What happens just before and after? Which thread is doing
what at that moment?


try with the latest snapshot. You can get it from

http://www.yqcomputer.com/


Good luck
--
Best regards :)

Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
 
 
 

FTP in Thread

Post by Martin Jam » Fri, 07 Apr 2006 02:25:18


9.0.14?

I'm fairly sure that I've used this version before in threads without nay
sleeps or other strangenesses. It worked fine. I'll try & make sure by
looking through my old projects.

Rgds,
Martin
 
 
 

FTP in Thread

Post by sham » Fri, 07 Apr 2006 21:20:31

Hi,

This is what I have done so far:

Simple server application which has a TidFTPServer component and a
OnStoreEvent that does a VStream := TFileStream(filename, fmCreate);

That is all.

Client App demo has no threads (taken them out) and loops 100 times and
sends files. I still get a readTimeOut on the client:

There are a number of threads running on the Server and two of them have the
stacks:
Thread 1 (on server)
TIdStackWindows.WSSelect(???,???,nil,???)
CheckIsReadable(4561208)
TIdSocketHandle.Readable(-2)
TIdIOHandlerSocket.Readable(???)
TIdTCPConnection.ReadFromStack(True,-2,True)
TIdTCPConnection.ReadLn(#$A,-1,16384)
TIdTCPServer.DoExecute($E24A38)
TIdPeerThread.Run
TIdThread.Execute


Thread 2 (on server)
TIdStackWindows.WSSelect(???,???,nil,???)
TIdSocketHandle.Select(???,4561208)
TIdServerIOHandlerSocket.Accept(1796,$E24718)
TIdListenerThread.Run
TIdThread.Execute


On the client the stack is:
(on client when time out occurs)
TIdTCPConnection.ReadFromStack(True,5000,True)
TIdTCPConnection.ReadLn(#$A,-1,16384)
TIdTCPConnection.ReadLnWait(2147483647)
TIdTCPConnection.GetInternalResponse
TIdTCPConnection.GetResponse((...))
TIdTCPConnection.SendCmd(???,???)
TIdFTP.SendPort($45A31C)
TIdFTP.InternalPut('STOR TestDemo5.dat-FS=11',$CF37D0,True)
TIdFTP.Put($CF37D0,'TestDemo5.dat-FS=11',False)
TForm1.Button1Click(???)
FTPSenderTest

I have upgraded to 9.0.18 but cannot go to 10 since it breaks some other
components.

We have got to the point where we are about to s *** indy.

Any help would be appreciated.

Sham.

Ps. I replaced the server with GuildFTP and there is no problem. So clearly
the problem is with the ftp server code.
 
 
 

FTP in Thread

Post by sham » Fri, 07 Apr 2006 22:32:05

urther to may last email:

Client :
procedure TForm1.Button1Click(Sender: TObject);
var
FFTPClient: TIdFTP;
i : integer;
FileList : TStringList;
currentDirectory : String;
FileStream : TFileStream;
filename : string;
sizeOfFile : integer;
begin
Button1.Enabled := False;

currentDirectory :=
IncludeTrailingPathDelimiter(ExtractFileDir(Application.ExeName));
for i := 1 to 100 do
begin
FileList := TStringList.Create;
try
FileList.Add('TestDemo' + intToStr(i));
fileName := currentDirectory + 'TestDemo' + intToStr(i) + '.dat';
FileList.SaveToFile(fileName);
finally
FileList.Free;
end;
end;

FFTPClient:= TIdFTP.create(nil);
try
FFTPClient.Host := '127.0.0.1';
FFTPClient.Port := 21;
FFTPClient.Username := 'abc';
FFTPClient.Password := '';
FFTPClient.TransferType := ftBinary;
FFTPClient.ReadTimeout := 5000;

FFTPClient.Connect();
try
for i := 1 to 100 do
begin
fileName := 'TestDemo' + intToStr(i) + '.dat';
FileStream := TFileStream.Create(fileName, fmOpenRead);
try
sizeOfFile := FileStream.Size;

FFTPClient.Put(FileStream, fileName + '-FS=' +
intToStr(sizeOfFile));
finally
FileStream.Free;
end;
end;

finally
FFTPClient.Disconnect;
end;
finally
FFTPClient.Free;
end;

Button1.Enabled := True;
end;

Server :

procedure TForm1.IdFTPServer1StoreFile(ASender: TIdFTPServerThread;
const AFileName: String; AAppend: Boolean; var VStream: TStream);
var
tempFileName : string;
begin
tempFileName := StringReplace(AFileName, '/', '\', [rfReplaceAll]);
VStream := TFileStream.Create('D:\data' + tempFileName, fmCreate);
end;

procedure TForm1.IdFTPServer1UserLogin(ASender: TIdFTPServerThread;
const AUsername, APassword: String; var AAuthenticated: Boolean);
begin
AAuthenticated := True;
end;

That is pretty much it.

I am using 9.0.18.

There must be some sort of problem in my enviornment if I cannot get this
working.
As I mentioned before, when I use GuildFTP, all seems fine.

Sham.

"sham" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...



 
 
 

FTP in Thread

Post by sham » Sun, 09 Apr 2006 22:33:18

ince I have not had any reply regarding the INDY problem I am having, are
there any other blocking FTP clients out there?

Sham.
"sham" < XXXX@XXXXX.COM > wrote in message
news:443518fc$ XXXX@XXXXX.COM ...


 
 
 

FTP in Thread

Post by Lukas Geba » Mon, 10 Apr 2006 18:44:01

 
 
 

FTP in Thread

Post by sham » Tue, 11 Apr 2006 01:37:10

Does synapse FTPSend have an onprogress event. I need to give feedback of
transfers.
 
 
 

FTP in Thread

Post by Lukas Geba » Tue, 11 Apr 2006 03:31:49


event: TFtpSend.DSock.OnStatus
 
 
 

FTP in Thread

Post by Guille » Tue, 11 Apr 2006 20:21:06


that's a very short timeout. Default value is 60000.

What kind of authentication are you using on the server?

OTOH I see you are not setting any proxy values. I guess you are not
working with any, are you?


where do you create the worker thread?


--
Best regards :)

Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
 
 
 

FTP in Thread

Post by sham » Tue, 11 Apr 2006 20:53:06

i Guillem,

I removed all the threading code and created two applications, one the FTP
Server and the other the FTP Client. I could not get this to work due to the
time outs and then sometimes getting the stack dumps that I have shown in
previous threads.

I am testing locally and have not proxy settings. For authentication, I just
code the onauthenticate event and accepted the login.

So, what am I doing wrong in this simple demo without threads?

Sham.

"Guillem" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...


 
 
 

FTP in Thread

Post by Francois P » Tue, 11 Apr 2006 23:51:18

> I removed all the threading code and created two applications, one the FTP
the

If you don't one to use multithreading and still be able to use a single
application having both FTP server and FTP client, then use ICS instead of
Indy. ICS has an asynchronous operating mode which let your application do
other things while communication take place. To have both client(s) and
server(s) in same program, just drop both components on a form and write a
few lines of code and event handlers. The components will multitask for you
automatically !

ICS is freeware with full source code. Download from http://www.yqcomputer.com/ .
Have a look at the FtpTst and FtpServ demos. Subribe to the support mailing
list if you have questions.
 
 
 

FTP in Thread

Post by sham » Wed, 12 Apr 2006 00:00:24

Thanks Francois (I have to get my postcard out to you),

I am currently exprimenting with ICS but the problem is we need blocking
components. The mulithreading side of the code works well and with the
timescales involved we cannot change the current model. To be honest when we
tested the indy client against the ICS ftp server, we saw exceptionally fast
transfers.

However, as I have been trying to find the answer to for over a week, I get
some weird errors even if I lose the multithreading and just try simple demo
apps with INDY. The problem must be with my environment since I cannot see
how it could be a problem with the INDY components as it would have been
reported by now.

At the moment I am using ICS for my FTP server and moving Synapse for the
ftp client.

Sham.





"Francois Piette [ICS & Midware]" < XXXX@XXXXX.COM > wrote in