Strange characters in TFtp:directory()

Strange characters in TFtp:directory()

Postby hua » Wed May 29, 2019 8:50 am

Hi guys,
Using an amended version of samples\ftpdir.prg to point to my server and view in xBrowse, I see many funny characters at the end of folder name.
How to get rid ofthem?

Image

Was using Harbour+FWH19.03+BCC7.3
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Strange characters in TFtp:directory()

Postby hmpaquito » Wed May 29, 2019 8:57 am

Hi,

https://forums.fivetechsupport.com/view ... 30&start=0

Sorry but,

1. Anwers in Spanish.
2. There is no (a clear) solution

Regards
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Strange characters in TFtp:directory()

Postby hua » Wed May 29, 2019 9:56 am

Thanks for the reply Paco. Yes neither HB_SETCODEPAGE( "UTF8" ) nor FW_SetUnicode(.T.) work for me too.

It actually seems to get worse. oFtp:directory() seems to even capture system message (see 4th line in xBrowse) with my repetitive test

Image
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Strange characters in TFtp:directory()

Postby hmpaquito » Wed May 29, 2019 10:25 am

I use a very bad workaround with success.

Looking for files with required extension,
Looking for Chr(0) (null) character at init line,
etc...

A clear of waste files.

But is strange... nobody warned about issue.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Strange characters in TFtp:directory()

Postby 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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 45 guests