BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

BCB6 Pro, Indy 9, IdFTPServer LIST problems

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
Paul at NCF
Guest





PostPosted: Sun Feb 18, 2007 6:01 pm    Post subject: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote



Hi,

I'm trying to understand how the IdFTPServer works and starting to build up
a small application, using windows xp FTP client to test it. I can get the
event handlers for connection, disconnection, login activities processed,
but DIR or LS seems to be very troublesome.

In the IdFTPServerAfterUserLogin handler I set the directories as follows (I
presume this is ok, or should be doing this some other way):

ASender->HomeDir = "C:\\MOS\\";
ASender->CurrentDir = "C:\\MOS\\Log\\"; or "C:\\MOS\\";

In the IdFTPServerListDirectory handler I print out the home, current, and
parameter APath. The APath seems to be rubbish, or has something appended.
I'm emulating DOS and the component properties seem to indicate this is in
use. Am I missing something or is this a known problem?

C:\MOS\
C:\MOS\Log\
C:\MOS\Log\//

The PAS file has a call to ProcessPath, is this a problem?

ListDirectory(TIdFTPServerThread(ASender.Thread),
ProcessPath(FCurrentDir
, ASender.UnparsedParams), LStream, ASender.CommandHandler =
FCmdHandlerList);

The ListDirectory does this, what is the Copy function doing?

LPathSep := '/'; {Do not Localize}
// Emulated System
case FEmulateSystem of
ftpsOther: begin
if Assigned(OnGetCustomListFormat) then begin
LDirectoryList.ListFormat := flfCustom;
LDirectoryList.OnGetCustomListFormat := DoGetCustomListFormat;
end else begin
LDirectoryList.ListFormat := flfNone;
end;
end;
ftpsDOS: begin
LDirectoryList.ListFormat := flfDos;
LPathSep := '\'; {Do not Localize}
end;
ftpsUNIX: begin
LDirectoryList.ListFormat := flfUnix;
end;
ftpsVAX: begin
LDirectoryList.ListFormat := flfVax;
end;
end;
if Copy(ADirectory, Length(LPathSep), 1) <> LPathSep then begin
ADirectory := ADirectory + LPathSep;
end;
// Event
FOnListDirectory(ASender, ADirectory, LDirectoryList);


Finally, whilst on this topic (althoug I'm sure it won't be my last, where
is the client IP connection data recorded, I can't see it in the
TIdFTPServerThread *ASender and TIdPeerThread *AThread parameters? Is it
accessible as I would like to validate client IP addresses, not just the
user accounts?

Regards,

Paul
Back to top
Paul at NCF
Guest





PostPosted: Mon Feb 19, 2007 3:50 pm    Post subject: Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote



Hi, I removed the setting of current directory, as I realised I shouldn't
do this, but the server still seems to be making the APath parameter include
a forward slash in the directory list event handler. Its almost as if the
property which sets the system type to DOS isn't being fully used and is
confused between unix and dos. Help!

Client Connected:
Client Login Requested:
guest
Client Logged On:
Home Dir:C:\
Current Dir:/
Client Requested Change Directory:
\mos
Client Requested Change Directory:
\mos
Client Requested Change Directory:
\mos\log
Client Requested Directory Listing:
C:\
\mos\log
\mos\log/
Client Disconnected:
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Feb 21, 2007 12:46 am    Post subject: Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote



"Paul at NCF" <notplmacca (AT) clara (DOT) co.uk> wrote in message
news:45d83fd9$1 (AT) newsgroups (DOT) borland.com...

Quote:
In the IdFTPServerAfterUserLogin handler I set the directories as
follows (I presume this is ok, or should be doing this some other
way):


You are using DOS-style path delimiters, but TIdFTPServer defalts to
Unix-style delimiters instead. That has a big influence on
TIdFTPServer's behavior. You can't mix the two together.

If you are using Indy 10, then I suggest you attach a TIdFTPFileSystem
instead of trying to parse everything yourself manually.

Quote:
In the IdFTPServerListDirectory handler I print out the home,
current, and
parameter APath. The APath seems to be rubbish, or has something
appended.
I'm emulating DOS and the component properties seem to indicate this
is in
use. Am I missing something or is this a known problem?

Since you did not show any of your code, there is no way to diagnose
your problem.

Quote:
The ListDirectory does this, what is the Copy function doing?

Comparing the last character in the string to the specified path
delimiter.

Quote:
where is the client IP connection data recorded, I can't see it in
the
TIdFTPServerThread *ASender and TIdPeerThread *AThread parameters?

TIdPeerThread.Connection.Socket.Binding.PeerIP


Gambit
Back to top
Paul at NCF
Guest





PostPosted: Wed Feb 21, 2007 3:23 pm    Post subject: Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote

Hi,

Quote:
You are using DOS-style path delimiters, but TIdFTPServer defalts to
Unix-style delimiters instead. That has a big influence on
TIdFTPServer's behavior. You can't mix the two together.

But I'm setting the server emulate property to DOS, does that not mean the
server doesn't change to use '\' instead of '/'?

Quote:
If you are using Indy 10, then I suggest you attach a TIdFTPFileSystem
instead of trying to parse everything yourself manually.

I'm using 9.0.50 I think, the last dev snapshot.

Quote:
Comparing the last character in the string to the specified path
delimiter.


Yes, so in DOS emulation mode it is checking or using '\' delimiter

Quote:
TIdPeerThread.Connection.Socket.Binding.PeerIP

Knew it had to be somewhere!

Quote:
Since you did not show any of your code, there is no way to diagnose
your problem.


I'm setting to DOS in design time. I'm using Windows XP FTP client to test
against. This is a prototype, not by any means a viable application, just
trying to get a feel for the component.

Maybe the FTP server is working ok and its just that APath doesn't look
right, but its ok. The client closes the connection after the DIR command.
What code needs to go in the dir event handler or (cd handler)?

//---------------------------------------------------------------------------
void __fastcall TMainForm::IdFTPServerConnect(TIdPeerThread *AThread)
{
AnsiString str = "Client Connected:";
DebugWindow->Lines->Add(str);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::IdFTPServerDisconnect(TIdPeerThread *AThread)
{
AnsiString str = "Client Disconnected:";
DebugWindow->Lines->Add(str);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::IdFTPServerUserLogin(
TIdFTPServerThread *ASender, const AnsiString AUsername,
const AnsiString APassword, bool &AAuthenticated)
{
bool result = false;

AnsiString str = "Client Login Requested:";
DebugWindow->Lines->Add(str);

// Verify User Name/Password
str = " " + AUsername + " " + APassword;
DebugWindow->Lines->Add(str);

if (AUsername == "ctsguest") result = true;

// Verify Remote Client

// logon result?
AAuthenticated = result;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::IdFTPServerAfterUserLogin(
TIdFTPServerThread *ASender)
{
AnsiString str = "Client Logged On:";
DebugWindow->Lines->Add(str);

//
ASender->HomeDir = "C:\\";

str = " Home Dir:" + ASender->HomeDir;
DebugWindow->Lines->Add(str);

str = " Current Dir:" + ASender->CurrentDir;
DebugWindow->Lines->Add(str);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::IdFTPServerListDirectory(
TIdFTPServerThread *ASender, const AnsiString APath,
TIdFTPListItems *ADirectoryListing)
{
AnsiString str = "Client Requested Directory Listing:";
DebugWindow->Lines->Add(str);

//
str = " " + ASender->HomeDir;
DebugWindow->Lines->Add(str);

str = " " + ASender->CurrentDir;
DebugWindow->Lines->Add(str);

str = " " + APath;
DebugWindow->Lines->Add(str);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::IdFTPServerChangeDirectory(
TIdFTPServerThread *ASender, AnsiString &VDirectory)
{
AnsiString str = "Client Requested Change Directory:";
DebugWindow->Lines->Add(str);

//
str = " " + VDirectory;
DebugWindow->Lines->Add(str);
}
//---------------------------------------------------------------------------

Debug output window looks like this:

System Running....
Client Connected:
Client Login Requested:
ctsguest
Client Logged On:
Home Dir:C:\
Current Dir:/
Client Requested Change Directory: (typed "cd \temp" in client)
\temp
Client Requested Directory Listing: (typed "dir" in client)
C:\
\temp
\temp/

OR

Client Connected:
Client Login Requested:
ctsguest
Client Logged On:
Home Dir:C:\
Current Dir:/
Client Requested Change Directory: (typed "cd /temp" in client)
/\/temp
Client Requested Directory Listing: (typed "dir" in client)
C:\
/\/temp
/\/temp/\
Client Disconnected:

Thanks

Paul
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 22, 2007 12:26 am    Post subject: Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote

"Paul at NCF" <notplmacca (AT) clara (DOT) co.uk> wrote in message
news:45dc0f7a (AT) newsgroups (DOT) borland.com...

Quote:
But I'm setting the server emulate property to DOS, does that
not mean the server doesn't change to use '\' instead of '/'?

On the server side, yes. But not on the client side. Most clients
use Unix style delimiters, because that is what URLs use in general.
You don't really have any control over that. My advise to you is to
use Unix style paths on the server as well. And don't use full paths
in the TIdFTPServerThread.CurrentDir property, either, if you can
avoid it. Yes, then means more work on your part when processing and
translating paths in the various server events. But it is a more
secure and more compatible approach.

I have posted examples of using TIdFTPServer before. For example:

http://groups.google.com/group/borland.public.cppbuilder.vcl.components.using/msg/aedff55eaac537d0

http://groups.google.com/group/borland.public.delphi.internet.winsock/browse_thread/thread/3c19ae8b4ac54c02/52dba2730a66773e?lnk=st&q=tidftpserver+group%3A*borland*+author%3Aremy+author%3Alebeau&rnum=13#52dba2730a66773e

Quote:
What code needs to go in the dir event handler or (cd handler)?

The OnListDirectory event is responsible for filling in the
TIdFTPListItems collection with the files and folders of the specified
directory.

The OnChangeDirectory event is responsible for validating, and
optionally modifying, the string that will be assigned to the
TIdFTPServerThread.CurrentDir property after the event handler exits.

Quote:
DebugWindow->Lines->Add(str);

That is not thread-safe. All of the server events are triggered in
the context of a worker thread, not the main thread. Access to GUI
controls needs to be synchronized, or unexpected things can happen.


Gambit
Back to top
Paul at NCF
Guest





PostPosted: Thu Feb 22, 2007 1:35 am    Post subject: Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote

Hi,

Quote:
You don't really have any control over that. My advise to you is to
use Unix style paths on the server as well.

Okay thanks, I'll change that and give it a try.

Quote:
I have posted examples of using TIdFTPServer before. For example:

Thanks.

Quote:
The OnListDirectory event is responsible for filling in the
TIdFTPListItems collection with the files and folders of the specified
directory.

Thanks. Hopefully your examples will help.

Quote:
The OnChangeDirectory event is responsible for validating, and
optionally modifying, the string that will be assigned to the
TIdFTPServerThread.CurrentDir property after the event handler exits.

Okay. So I guess if the server decides that the directory is inhibited or
non existent, it can change it?
eg. change VDirectory param to current path rather than path requested?
And/or can you send a failure response to the request?

Quote:
That is not thread-safe. All of the server events are triggered in
the context of a worker thread, not the main thread. Access to GUI
controls needs to be synchronized, or unexpected things can happen.

Okay. I'll modify the code.
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 22, 2007 3:02 am    Post subject: Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems Reply with quote

"Paul at NCF" <notplmacca (AT) clara (DOT) co.uk> wrote in message
news:45dc9ebe (AT) newsgroups (DOT) borland.com...

Quote:
So I guess if the server decides that the directory is inhibited or
non existent, it can change it?

If the directory is not allowed, then the event handler has to throw
an exception so an error message is sent to the client.

Quote:
And/or can you send a failure response to the request?

Throw an exception containing the desired error message.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.