ListDirData Event - WeOnlyDo Discussion board

ListDirData Event (wodSFTP / wodSFTP.NET / wodSFTPdll)

by David Lucas, Tuesday, December 21, 2010, 11:52 (4847 days ago)

I'm using the wodFTPD COM object in C++ Builder 6 and I'm trying to get it to list different files than it would by default. Here's my event handler, can you tell me where I'm going wrong (and perhaps provide or point me to an example):

void __fastcall TForm1::ServerListDirData(TObject * Sender, IFtpUser* User,
LPSAFEARRAY* DirData, VARIANT_BOOL NamesOnly)
{
SAFEARRAYBOUND saBound[1];
saBound[0].lLbound = 1;
saBound[0].cElements = 1;

*DirData = SafeArrayCreate(VT_VARIANT, 1, saBound);
SafeArrayLock(*DirData);

long lx = 1;
VARIANT *pVar = NULL;
SafeArrayPtrOfIndex(*DirData, &lx, (void**)&pVar);

if(pVar)
{
pVar->vt = VT_BSTR;
pVar->bstrVal = ::SysAllocString(WideString(ClientFileList));
}

SafeArrayUnlock(*DirData);

NamesOnly = false;
}


ClientFileList is actually one long AnsiString that I build up by calling ListDir on a wodFTP COM object (i.e. the client object).

Re: ListDirData Event

by woddrazen, Tuesday, December 21, 2010, 12:17 (4847 days ago) @ David Lucas

Hi David,


We have some simple ListDirData sample for VB6.
[code]Private Sub FtpD_ListDirData(ByVal User As wodFTPDComLib.IFtpUser, DirData() As Byte, ByVal NamesOnly As Boolean)
Dim out As String

NamesOnly = True

out = out + -rw-rw-rw 1 root root 449 Aug 18 14:04 test.txt + vbLf
out = out + -rw-rw-rw 1 root root 40939 Jan 18 12:02 test.html

DirData = StrConv(out, vbFromUnicode)
End Sub[/code]
Is there any chance you can try something like that in C++ builder?

Let us know how it goes.


Regards,
Drazen

Re: ListDirData Event

by David Lucas, Wednesday, December 22, 2010, 09:43 (4846 days ago) @ woddrazen

Thank you for the example, unfortunately it didn't help much, but I was having a look at the source code for wodFTPD and I've made a little more progress.

My event handler now looks like this:

void __fastcall TForm1::ServerListDirData(TObject * Sender, IFtpUser* User,
OleVariant &DirData, OleVariant &NamesOnly)
{
AnsiString ClientFileList = -rw-rw-rw 1 root root 449 Aug 18 14:04 test.txt

rw-rw-rw 1 root root 40939 Jan 18 12:02 test.html ;

DirData.ArrayRedim(ClientFileList.Length()+1);

void *pBuff = DirData.ArrayLock();
memcpy(pBuff, ClientFileList.c_str(), ClientFileList.Length());
((char*)pBuff)[ClientFileList.Length()] = '';
DirData.ArrayUnlock();

NamesOnly.VBoolean = true;
}


While this actually changes what my client displays (I'm using WinSCP), it's still not right, as the file names come out as follows:
-rw-rw-rw 1 root root 449 Aug 18 14:04 test.txt rather than just text.txt .

Any suggestions? I'm using a fairly old version, 2.1.9.103, but couldn't see anything in the release notes regarding the ListDirData event.


Regards,

David Lucas

Re: ListDirData Event

by David Lucas, Wednesday, December 22, 2010, 09:45 (4846 days ago) @ David Lucas

I've noticed that the back/forward slashes are being stripped from my messages (in my even handler above), but they are there.

Re: ListDirData Event

by wodDamir, Wednesday, December 22, 2010, 09:55 (4846 days ago) @ David Lucas

David,

What happens if you set NamesOnly parameter to false?

Regards,
Damba

Re: ListDirData Event

by David Lucas, Wednesday, December 22, 2010, 10:11 (4846 days ago) @ wodDamir

David,

What happens if you set NamesOnly parameter to false?

Regards,
Damba

The same thing unfortunately.

Re: ListDirData Event

by David Lucas, Wednesday, December 22, 2010, 10:35 (4846 days ago) @ David Lucas

I didn't mention that I'm running the FTP server in SSH mode. I've just tried it in standard FTP mode and it seems to work.

I'll have to try a few different browsers to confirm that.

Re: ListDirData Event

by David Lucas, Wednesday, December 22, 2010, 10:45 (4846 days ago) @ David Lucas

I didn't mention that I'm running the FTP server in SSH mode. I've just tried it in standard FTP mode and it seems to work.

I'll have to try a few different browsers to confirm that.

I just tried browsing to my wodFTPD application using IE and it seems the file names are still displaying incorrectly, even in standard FTP mode.

Re: ListDirData Event

by David Lucas, Wednesday, December 22, 2010, 11:21 (4846 days ago) @ David Lucas

Sort of making progress, the following works properly with IE if wodFTPD is in normal FTP mode, but still doesn't come out right in SFTP mode:

void __fastcall TForm1::ServerListDirData(TObject * Sender, IFtpUser* User,
OleVariant &DirData, OleVariant &NamesOnly)
{
AnsiString ClientFileList = -rw-rw-rw- 1 root root 449 Aug 18 14:04 test.txt

-rw-rw-rw- 1 root root 40939 Jan 18 12:02 test.html ;

DirData.ArrayRedim(ClientFileList.Length()+1);

void *pBuff = DirData.ArrayLock();
memcpy(pBuff, ClientFileList.c_str(), ClientFileList.Length());
((char*)pBuff)[ClientFileList.Length()] = '';
DirData.ArrayUnlock();

NamesOnly.VBoolean = false;
}

The minus symbols on the end of the permissions were missing in your example which meant it wasn't formatting correctly in IE. However, still no joy in getting it to work properly when the protocol is set to SFTP.

Re: ListDirData Event

by wodDamir, Wednesday, December 22, 2010, 11:27 (4846 days ago) @ David Lucas

David,

Please try the following in C Builder:

[code]Dim out As String

If NamesOnly = False Then
out = -rw-rw-rw- 1 root root 67745 Sep 2 2007 test.txt + vbLf
out = out + -rw-rw-rw- 1 root root 43343 Dec 16 12:57 test.html + vbLf
Else
out = test.txt + vbLf
out = out + test.html + vbLf
End If

DirData = StrConv(out, vbFromUnicode)[/code]

It works in SFTP for me.

Regards,
Damba