Board index » delphi » TIdFTP Problems...

TIdFTP Problems...


2006-08-29 05:55:30 AM
delphi186
I'm having problems with TIdFTP - maybe someone could help. I am using D2006
Professional with the Indy components that come with the standard install
(10.1.5 I believe). The code I am using is below. It basically just
connects, lists a directory and gets a file. However sometimes (not
always?!?) I get a EIdReplyRFCError with mesasage "7: command not
understood. Any idea what's going on? Am I not closing the connection?
Should I have AutoLogin set to True? Are there any basic demos that I can
use to just upload and download a file?
All help greatly appreciated!
Steve
// LOADING A FILE
f := ''SOME_FILE.horizon';
s := TStringList.Create;
idFTP1.Disconnect;
idFTP1.Host := '<xxxxx.xxxxx.xxxx>';
idFTP1.Username := '<USERNAME>';
idFTP1.Password := '<PASSWORD>';
idFTP1.Connect;
idFTP1.ChangeDir('Horizon');
idFTP1.List(s);
// Is there a new file to on the network
if (s.IndexOf(f)>= 0) then
begin
idFTP1.Get(f, f, true);
<DO SOMETHING WITH IT>
end;
finally
idFTP1.Abort;
idFTP1.Disconnect;
idFTP1.Quit;
s.Free;
end;
//SAVING A FILE
try
idFTP1.Disconnect;
idFTP1.Host := 'HOST'
idFTP1.Username := '<USERNAME>';
idFTP1.Password := '<PASSWORD>';
idFTP1.Connect;
idFTP1.ChangeDir('Horizon');
idFTP1.Put(cParticipant.NormalFileName);
finally
idFTP1.Abort;
idFTP1.Disconnect;
idFTP1.Quit;
end;
// COMPONENTS PROPERTIES
with IdFTP1 do
begin
Name := 'IdFTP1';
AutoLogin := True;
Host := '<HOST>';
Password := '<PASSWORD>';
TransferTimeout := 20000;
Username := 'USERNAME';
ProxySettings.ProxyType := fpcmNone;
ProxySettings.Port := 0;
ReadTimeout := 5000;
end;
 
 

Re:TIdFTP Problems...

"Steve M" <XXXX@XXXXX.COM>writes
Quote
However sometimes (not always?!?) I get a EIdReplyRFCError
with mesasage "7: command not understood.
At what point exactly? Please be more specific. Which EXACT line is the
exception coming from?
Quote
Am I not closing the connection?
Why are you calling Abort()? Why are you calling Disconnect() and Quit()
together?
Quote
Should I have AutoLogin set to True?
If you do not set AutoLogin to true, then you must call Login() yourself
after Connect() exits. You must authenticate yourself with the server
before you can do anything with it. Even anonymous logins require
authentication.
Use this code instead:
--- downloading ---
f := 'SOME_FILE.horizon';
s := TStringList.Create;
try
idFTP1.Host := '<xxxxx.xxxxx.xxxx>';
idFTP1.Username := '<USERNAME>';
idFTP1.Password := '<PASSWORD>';
idFTP1.Connect;
try
idFTP1.ChangeDir('Horizon');
idFTP1.List(s);
if (s.IndexOf(f) <>-1) then
begin
idFTP1.Get(f, 'c:\some folder\' + f, true);
// ...
end;
finally
idFTP1.Quit;
end;
finally
s.Free;
end;
--- uploading ---
idFTP1.Host := 'HOST'
idFTP1.Username := '<USERNAME>';
idFTP1.Password := '<PASSWORD>';
idFTP1.Connect;
try
idFTP1.ChangeDir('Horizon');
idFTP1.Put(cParticipant.NormalFileName);
finally
idFTP1.Quit;
end;
Gambit
 

Re:TIdFTP Problems...

Remy,
Thanks for the quick reply! I will take a look at the code. I also changed
the mode to 'passive' based on another post here in the newsgroup and that
seems to have done the trick.
I'll let you know how I get on. BTW When I compile the application with
FastMM4 in memory leak checking mode it indicates that TIdFTP leaks - are
you aware of this? it is not much, so probably isn't a big problem.
Thanks again,
Steve
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Steve M" <XXXX@XXXXX.COM>writes
news:44f3665a$XXXX@XXXXX.COM...

>However sometimes (not always?!?) I get a EIdReplyRFCError
>with mesasage "7: command not understood.

At what point exactly? Please be more specific. Which EXACT line is the
exception coming from?

>Am I not closing the connection?

Why are you calling Abort()? Why are you calling Disconnect() and Quit()
together?

>Should I have AutoLogin set to True?

If you do not set AutoLogin to true, then you must call Login() yourself
after Connect() exits. You must authenticate yourself with the server
before you can do anything with it. Even anonymous logins require
authentication.

Use this code instead:


--- downloading ---

f := 'SOME_FILE.horizon';
s := TStringList.Create;
try
idFTP1.Host := '<xxxxx.xxxxx.xxxx>';
idFTP1.Username := '<USERNAME>';
idFTP1.Password := '<PASSWORD>';
idFTP1.Connect;
try
idFTP1.ChangeDir('Horizon');
idFTP1.List(s);
if (s.IndexOf(f) <>-1) then
begin
idFTP1.Get(f, 'c:\some folder\' + f, true);
// ...
end;
finally
idFTP1.Quit;
end;
finally
s.Free;
end;


--- uploading ---

idFTP1.Host := 'HOST'
idFTP1.Username := '<USERNAME>';
idFTP1.Password := '<PASSWORD>';
idFTP1.Connect;
try
idFTP1.ChangeDir('Horizon');
idFTP1.Put(cParticipant.NormalFileName);
finally
idFTP1.Quit;
end;


Gambit


 

Re:TIdFTP Problems...

"Steve M" <XXXX@XXXXX.COM>writes
Quote
BTW When I compile the application with FastMM4 in memory
leak checking mode it indicates that TIdFTP leaks - are you aware
of this?
Please be more specific. There are a couple of "intentional" leaks in Indy.
But you need to provide more details about the leak you are seeing in order
to know whether it is one of the known leaks or not.
Gambit
 

Re:TIdFTP Problems...

Remy,
I've tries your code and setting the control to Passive and this seems to
work. Thanks!
As for the memory leaks, when the application exits and I am returned to the
IDE I get a message saying that there are small block leaks:
1 - 12 bytes: TIdThreadSafeInteger x 1
21 - 28 bytes: TIdCriticalSecton x 2
Mnay thanks,
Steve Maughan
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>writes
Quote

"Steve M" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>BTW When I compile the application with FastMM4 in memory
>leak checking mode it indicates that TIdFTP leaks - are you aware
>of this?

Please be more specific. There are a couple of "intentional" leaks in
Indy.
But you need to provide more details about the leak you are seeing in
order
to know whether it is one of the known leaks or not.


Gambit


 

Re:TIdFTP Problems...

"Steve M" <XXXX@XXXXX.COM>writes
Quote
As for the memory leaks, when the application exits and I am returned to
the
IDE I get a message saying that there are small block leaks:

1 - 12 bytes: TIdThreadSafeInteger x 1
21 - 28 bytes: TIdCriticalSecton x 2
There is one TIdThreadSafeInteger leak in IdThread.pas, and one
TIdCriticalSection leak in IdStack.pas. Both leaks are intentional, as
described in the comments in those files.
I have no clue where the second TIdCriticalSection leak could be coming
from. You need to provide more details about that.
Gambit