by hua » Tue Aug 20, 2019 8:01 am
Solved. At least, for my requirement it's good enough.
The file name in oFtp:cFilename is a null-terminated string. So I assume whatever after the null character is left overs in memory.
I ammended oFtp:directory() function to retrieve the filename up to the null character only.
method Directory( cMask ) CLASS TFtp
local hFTPDir, aFiles := {}
local oWin32FindData, cBuffer
DEFAULT cMask := "*.*"
STRUCT oWin32FindData
MEMBER nFileAttributes AS DWORD
MEMBER nCreationTime AS STRING LEN 8
MEMBER nLastReadAccess AS STRING LEN 8
MEMBER nLastWriteAccess AS STRING LEN 8
MEMBER nSizeHight AS DWORD
MEMBER nSizeLow AS DWORD
MEMBER nReserved0 AS DWORD
MEMBER nReserved1 AS DWORD
MEMBER cFileName AS STRING LEN 260
MEMBER cAltName AS STRING LEN 14
MEMBER nFileType AS DWORD
MEMBER nCreatorType AS DWORD
MEMBER nFinderFlags AS WORD
ENDSTRUCT
if ::hFTP != nil
cBuffer = oWin32FindData:cBuffer
hFTPDir = FtpFindFirstFile( ::hFTP, cMask, @cBuffer, hb_BitOr(INTERNET_FLAG_RELOAD, INTERNET_FLAG_NO_CACHE_WRITE), 0 )
oWin32FindData:cBuffer = cBuffer
if ! Empty( StripFromNull(oWin32FindData:cFileName) )
AAdd( aFiles, { StripFromNull(oWin32FindData:cFileName),;
oWin32FindData:nSizeLow,;
FileTimeToDate( oWin32FindData:nLastWriteAccess ),;
FileTimeToTime( oWin32FindData:nLastWriteAccess ) } )
while InternetFindNextFile( hFTPDir, @cBuffer )
oWin32FindData:cBuffer = cBuffer
AAdd( aFiles, { StripFromNull(oWin32FindData:cFileName),;
oWin32FindData:nSizeLow,;
FileTimeToDate( oWin32FindData:nLastWriteAccess ),;
FileTimeToTime( oWin32FindData:nLastWriteAccess ) } )
end
endif
InternetCloseHandle( hFTPDir )
endif
return aFiles
function StripFromNull(str)
local nPos := at(chr(0), str), cRet := ""
if !empty(str)
if nPos > 0
cRet := left(str, nPos-1)
endif
endif
return cRet
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour