Thread View: borland.public.cppbuilder.internet.socket
7 messages
7 total messages
Started by Paul at NCF
Sun, 18 Feb 2007 12:01
BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Paul at NCF
Date: Sun, 18 Feb 2007 12:01
Date: Sun, 18 Feb 2007 12:01
69 lines
3365 bytes
3365 bytes
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
Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Paul at NCF
Date: Mon, 19 Feb 2007 09:50
Date: Mon, 19 Feb 2007 09:50
23 lines
1689 bytes
1689 bytes
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:
Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Remy Lebeau (TeamB)
Date: Tue, 20 Feb 2007 18:46
Date: Tue, 20 Feb 2007 18:46
39 lines
2221 bytes
2221 bytes
"Paul at NCF" <notplmacca@clara.co.uk> wrote in message news:45d83fd9$1@newsgroups.borland.com... > 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. > 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. > The ListDirectory does this, what is the Copy function doing? Comparing the last character in the string to the specified path delimiter. > 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
Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Paul at NCF
Date: Wed, 21 Feb 2007 09:23
Date: Wed, 21 Feb 2007 09:23
151 lines
5510 bytes
5510 bytes
Hi,
> 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 '/'?
> 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.
> Comparing the last character in the string to the specified path
> delimiter.
Yes, so in DOS emulation mode it is checking or using '\' delimiter
> TIdPeerThread.Connection.Socket.Binding.PeerIP
Knew it had to be somewhere!
> 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
Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Remy Lebeau (TeamB)
Date: Wed, 21 Feb 2007 18:26
Date: Wed, 21 Feb 2007 18:26
40 lines
2820 bytes
2820 bytes
"Paul at NCF" <notplmacca@clara.co.uk> wrote in message news:45dc0f7a@newsgroups.borland.com... > 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 > 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. > 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
Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Paul at NCF
Date: Wed, 21 Feb 2007 19:35
Date: Wed, 21 Feb 2007 19:35
31 lines
2198 bytes
2198 bytes
Hi, > 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. > I have posted examples of using TIdFTPServer before. For example: Thanks. > 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. > 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? > 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.
Re: BCB6 Pro, Indy 9, IdFTPServer LIST problems
Author: Remy Lebeau (TeamB)
Date: Wed, 21 Feb 2007 21:02
Date: Wed, 21 Feb 2007 21:02
16 lines
1456 bytes
1456 bytes
"Paul at NCF" <notplmacca@clara.co.uk> wrote in message news:45dc9ebe@newsgroups.borland.com... > 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. > And/or can you send a failure response to the request? Throw an exception containing the desired error message. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads