Board index » delphi » TrivalFTPServer example ?

TrivalFTPServer example ?


2006-06-05 05:30:46 AM
delphi105
hi, does anybody know of an example on how to use the indy trival ftp
client/server components?
the website www.indyproject.org/ is currently down and there is next
to no documentation on this component.
i keep getting range check errors with the write event, which is why i want
to make sure I am using the component correctly.
if there is a bug in this component (i'm using the build issued with delphi
2006), is there a proper example on how to use the normal ftp server
component?
 
 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
the website www.indyproject.org/ is currently down
That is because it was recently moving to a new server. It is back online
now.
Quote
i keep getting range check errors with the write event
Please show your actual code. Which version of Indy are you using? How
large are the files you are trying to send?
Quote
if there is a bug in this component (i'm using the build issued
with delphi 2006)
Indy 9 or 10, though? BDS 2006 ships with both. Either way, the
development snapshots for both on www.indyproject.org are a little
bit newer than the ones that ship with BDS.
Gambit
 

Re:TrivalFTPServer example ?

thank you very much for your reply, Remy.
i'm really stuck with the 'put' event handler.
here is some code to try and work out what's going on... all i get is a
timeout (although a 'get' works fine).
i've changed the threadedevent property to true, and as you can see both the
client and server is on the same machine, communicating via the loopback
address:
i haven't been able to find anything much about this component on the indy
website faq.
this appears to be the best solution to my config settings problem - i won't
need to sent files any bigger than 4096 bytes, but the files I am sending in
this example are less than 100 bytes.
please help!
type
TForm1 = class(TForm)
IdTrivialFTPServer1: TIdTrivialFTPServer;
IdTrivialFTP1: TIdTrivialFTP;
Button1: TButton;
Button2: TButton;
procedure IdTrivialFTPServer1ReadFile(Sender: TObject; var FileName:
string; const PeerInfo: TPeerInfo;
var GrantAccess: Boolean; var AStream: TStream; var
FreeStreamOnComplete: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure IdTrivialFTPServer1WriteFile(Sender: TObject; var FileName:
string; const PeerInfo: TPeerInfo;
var GrantAccess: Boolean; var AStream: TStream; var
FreeStreamOnComplete: Boolean);
procedure Button2Click(Sender: TObject);
procedure IdTrivialFTPServer1TransferComplete(Sender: TObject; const
Success: Boolean; const PeerInfo: TPeerInfo;
var AStream: TStream; const WriteOperation: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
teststream : tmemorystream;
procedure TForm1.Button1Click(Sender: TObject);
begin
idtrivialftp1.Get('whatever.txt', 'c:\output.txt');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
idtrivialftp1.Put('c:\output.txt', 'upload.txt');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
teststream := tmemorystream.Create;
teststream.LoadFromFile('c:\test.txt');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
// teststream.Free;
end;
procedure TForm1.IdTrivialFTPServer1ReadFile(Sender: TObject; var FileName:
string; const PeerInfo: TPeerInfo;
var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete:
Boolean);
begin
grantaccess := true;
freestreamoncomplete := false;
astream := teststream;
astream.Position := 0;
end;
procedure TForm1.IdTrivialFTPServer1TransferComplete(Sender: TObject; const
Success: Boolean; const PeerInfo: TPeerInfo;
var AStream: TStream; const WriteOperation: Boolean);
begin
if assigned(astream) then astream.Free;
end;
procedure TForm1.IdTrivialFTPServer1WriteFile(Sender: TObject; var FileName:
string; const PeerInfo: TPeerInfo;
var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete:
Boolean);
var
outps: tmemorystream;
begin
showmessage(filename);
grantaccess := true;
freestreamoncomplete := true;
outps := tmemorystream.Create;
astream := outps;
{freestreamoncomplete := false;
//
astream.Position := 0;
outps := tmemorystream.create;
outps.CopyFrom(astream, astream.size);
outps.Position := 0;
outps.SaveToFile('c:\'+filename);
outps.Free; }
end;
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Mark" <XXXX@XXXXX.COM>writes
news:44835101$XXXX@XXXXX.COM...

>the website www.indyproject.org/ is currently down

That is because it was recently moving to a new server. It is back online
now.

>i keep getting range check errors with the write event

Please show your actual code. Which version of Indy are you using? How
large are the files you are trying to send?

>if there is a bug in this component (i'm using the build issued
>with delphi 2006)

Indy 9 or 10, though? BDS 2006 ships with both. Either way, the
development snapshots for both on www.indyproject.org are a little
bit newer than the ones that ship with BDS.


Gambit


 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
getting rid of the messagebox stops the timeout from happening,
but I am now getting a range check error.
Where?
Gambit
 

Re:TrivalFTPServer example ?

getting rid of the messagebox stops the timeout from happening, but I am now
getting a range check error.
any ideas?
 

Re:TrivalFTPServer example ?

in the onwritefile handler on the ftp server component:
procedure TForm1.IdTrivialFTPServer1WriteFile(Sender: TObject; var FileName:
string; const PeerInfo: TPeerInfo;
var GrantAccess: Boolean; var AStream: TStream; var FreeStreamOnComplete:
Boolean);
var
outps: tmemorystream;
begin
Quote
>showmessage(filename);
grantaccess := true;
freestreamoncomplete := true;
i can not see where the range check is happening, though?
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Mark" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>getting rid of the messagebox stops the timeout from happening,
>but I am now getting a range check error.

Where?


Gambit


 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
i can not see where the range check is happening, though?
Which line specifically is the de{*word*81} pointing to when it occurs?
Gambit
 

Re:TrivalFTPServer example ?

the exception happens on: idtrivialftp1.Put('c:\output.txt', 'upload.txt');
i can not determine if the error is in the idtrivialftp.put method, or in the
server onwrite handler.
i've had a look at the source of these units and i can not see anything
obvious which is staring me in the face as wrong.
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Mark" <XXXX@XXXXX.COM>writes
news:44846cf8$XXXX@XXXXX.COM...

>i can not see where the range check is happening, though?

Which line specifically is the de{*word*81} pointing to when it occurs?


Gambit


 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
the exception happens on: idtrivialftp1.Put('c:\output.txt',
'upload.txt');
Then the server has nothing to do with that at all.
Quote
i can not determine if the error is in the idtrivialftp.put method,
or in the server onwrite handler.
You just said where it is - in the Put().
Gambit
 

Re:TrivalFTPServer example ?

i've seperated the client/server applications and the range check exception
is definately happening in the idtrivialftp1.Put('c:\unit1.pas',
'eggs.txt') method.
i'll try using the overloaded method with a stream instead to see if that
variant is causing the problem.
"Mark" <XXXX@XXXXX.COM>writes
Quote
the exception happens on: idtrivialftp1.Put('c:\output.txt',
'upload.txt');

i can not determine if the error is in the idtrivialftp.put method, or in
the server onwrite handler.

i've had a look at the source of these units and i can not see anything
obvious which is staring me in the face as wrong.


"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
news:44848a15$XXXX@XXXXX.COM...
>
>"Mark" <XXXX@XXXXX.COM>writes
>news:44846cf8$XXXX@XXXXX.COM...
>
>>i can not see where the range check is happening, though?
>
>Which line specifically is the de{*word*81} pointing to when it occurs?
>
>
>Gambit
>
>


 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
i'll try using the overloaded method with a stream instead
to see if that variant is causing the problem.
Put(String, String) calls Put(Stream, String), so any problem would have to
be inside of Put(Stream, String) somewhere.
You never answered by earlier question about which SPECIFIC version and
build of Indy you are actually using. One usual cause of range check errors
is in sending 64-bit streams, since Indy's progress tracking events haven't
supported 64-bit values until a week ago when the Indy 10 snapshot was
updated to make the OnWork events use Int64 instead of Integer. Other than
that, I don't see anything else offhand that could be causing it. The only
way is you will just have to trace into Indy's source code with the de{*word*81}
and find the exact values that are going out of range.
Gambit
 

Re:TrivalFTPServer example ?

you're right. this code creates 'upload.txt' on the server, but it is zero
bytes. the faulty code exists somewhere in the put method... any clues at to
what is causing the problem?
i used both idtrivialftp1.put(stream, serverfile) and
idtrivialftp1.put(localfile, serverfile); and it still fails with a range
check error. it looks like somewhere an assumption is being made about the
size of a buffer or stream. the files I am uploading are only a few bytes in
size. I am leaving the block and buffer size properities as their defaults on
the components. I have tried smaller values, but to no avail.
is there anything i can do to try and get this working?
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Mark" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>the exception happens on: idtrivialftp1.Put('c:\output.txt',
'upload.txt');

Then the server has nothing to do with that at all.

>i can not determine if the error is in the idtrivialftp.put method,
>or in the server onwrite handler.

You just said where it is - in the Put().


Gambit


 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
this code creates 'upload.txt' on the server, but it is zero bytes.
The code you showed earlier is not actually writing to the file. You
commented all of that code out. It is not even creating the file at all.
Gambit
 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
looking at the code for the onwrite event handler, it seems that
if i assign nil to the astream value and change the filename, the
file creation happens automatically for me.
If you do not provide your own stream, TIdTrivialFTPServer does create its
own TIdFileCreateStream internally.
Gambit
 

Re:TrivalFTPServer example ?

"Mark" <XXXX@XXXXX.COM>writes
Quote
i'm using build 10.1.5 - the version which came with the rtm
release of bds 2006.
Then you are not using the latest build. The development snapshot on Indy's
website is newer.
Gambit