List Method
Class: FTP_SERVICE
Get detail list of folders and files.
=
Object.List
Parameter
luData
Local file name, string or array
Type Character/Array
By reference  
Direction Input
This parameter is depends on parameter liFlags. For more informations see to example part.
This parameter cannot be empty.
If is parameter liFlags
  • _FTPS_RWF_File - The parametr is file name. The result will be save as file.
  • _FTPS_RWF_String - The parameter is string and must be send by reference. The result will be save as string.
  • _FTPS_RWF_Array - The parameter is array and must be send by reference. The result will be save as array. Each row of array contain informations about a file or folder name. The format of array is:
    ColumnDescriptionType
    laArray(x,1) File AttributesString
    laArray(x,2) Links countNumber
    laArray(x,3) OwnerString
    laArray(x,4) GroupString
    laArray(x,5) File SizeNumber
    laArray(x,6) File Last Write TimeDateTime
    laArray(x,7) File NameString
    Parsing to array do after calling event FTP_SERVICE::AfterList().
lcMask
Mask for selecting folders and files
Type Character
Direction Input
Don't set this parameter if output is to array, because parser can failed at parsing.
liFlags
Mode flags
Type Boolean
Direction Input
Optional  
This parameter define type of first parameter luData. List of types
ValueDescription
_FTPS_RWF_File luData is file name.
_FTPS_RWF_String luData is string.
_FTPS_RWF_Array luData is array.
lnFlag
The flags that indicate various options.
Type Numeric
Direction Input
Optional  
A passed value is equal to dwFlags parameter of API function. If this parameter ommited, then default value is FTP_TRANSFER_TYPE_UNKNOWN . Can be one of the following:
ValueDescription
FTP_TRANSFER_TYPE_ASCII Transfers the file as ASCII.
FTP_TRANSFER_TYPE_BINARY Transfers the file as binary.
Assumed from MSDN.
Return value Boolean
The return value is .T. if list is downloaded or .F. is not.
Example
LOCAL loFTP
LOCAL ARRAY laFiles(1),laFile(1)

#INCLUDE "ftp.h"
SET PROCEDURE TO ftp.prg ADDITIVE 
loFTP=CREATEOBJECT('_myftp') 

IF loFTP.OpenInternet("anonymous", "gorila@gorila.cz","192.168.2.21", "21")

    * Get "Name list" and save it as file
    =loFTP.List("c:\nlstx.txt","",_FTPS_RWF_File,0)
    MODI FILE "c:\nlst.txt" NOWAIT


    * Get "Name list" and return it as string
    =loFTP.List(@lcPom,"",_FTPS_RWF_String,0)
    ?lcPom


    * Get "Name list" and save it to array
    ?loFTP.List(@laFiles,"download",_FTPS_RWF_Array,0)

    * For each file get other informations
    FOR lii=1 to ALEN(laFiles)
        ?
        ?laFiles[lii, 1]
        ?laFiles[lii, 2]
        ?laFiles[lii, 3]
        ?laFiles[lii, 4]
        ?laFiles[lii, 5]
        ?laFiles[lii, 6]
        ?laFiles[lii, 7]
    NEXT

   =loFTP.CloseInternet() 
ENDIF
RELEASE PROCEDURE ftp.prg

DEFINE CLASS _myFTP AS FTP_SERVICE
   PROCEDURE BeforeList(luData,lcMask,liFlags,lnFlag)
      ?PROGRAM(16)
      ?CHR(9),luData,lcMask,liFlags,lnFlag
   ENDPROC

   PROCEDURE AfterList(luData,lcMask,liFlags,lnFlag,liResult)
      ?PROGRAM(16)
      ?CHR(9),luData,lcMask,liFlags,lnFlag,liResult
   ENDPROC

   PROCEDURE AtList(luData,lcMask,liFlags,lnFlag,lcBuffer,liResult)
      ?PROGRAM(16)
      ?CHR(9),luData,lcMask,liFlags,lnFlag,lcBuffer,liResult
   ENDPROC
ENDDEFINE 
See also
Expand/Collapse source code of procedure List Source Code
      LPARAMETERS OUTREF luData, INP lcMask,OPT_INP liFlags,OPT_INP lnFlag
      EXTERNAL ARRAY luData
      LOCAL liResult, lihFTP,lii,lcBuffer,lcData,liData,liEnd,liCount,llRet

      liFlags=IIF(PCOUNT()<3,_FTPS_RWF_File,liFlags)
      lnFlag=IIF(PCOUNT()<4,FTP_TRANSFER_TYPE_ASCII,lnFlag)

      IF This.OpenFTPConnection(This.cCurrentDir)     && Open an FTP Handle
         IF BITTEST(liFlags,2) && Array?
            DIMENSION luData [1, 1]
            luData [1, 1] = .NULL.
         ENDIF
         lihFTP=0

         This.BeforeList(@luData,@lcMask,liFlags,lnFlag)

         liResult=IIF(This._FTPCommand("LIST "+lcMask,FTP_TRANSFER_TYPE_ASCII,0,@lihFTP),1,0)
         IF liResult #0 && OK, FTP list is openned
            llRet=.T.         
            lii=0
            liData=500
            STORE 1 TO fResult,liRead
            lcData=""

            DO WHILE liRead>0
               liRead=0
               lcBuffer=SPACE(liData)
               liResult = InternetReadFile(lihFTP, @lcBuffer, liData, @liRead)
               =This.GetExtendedError()
               This.AtList(@luData,@lcMask,liFlags,lnFlag,@lcBuffer,liResult)

               lcData=lcData+LEFT(lcBuffer,liRead)
               lii=lii+liRead
            ENDDO
            =InternetCloseHandle(lihFTP)  

            =This.AfterList(luData,lcMask,liFlags,lnFlag,liResult)

            DO CASE
               CASE liResult=0

               CASE !BITTEST(liFlags,0) AND !BITTEST(liFlags,2) && File?
                    IF STRTOFILE(lcData,luData)=0
                       This.SetExtendedError(_FTPS_UE_CWF,"")
                       llRet=.F.
                    ENDIF

               CASE BITTEST(liFlags,0) && String?
                    luData=lcData

               CASE BITTEST(liFlags,2) && Array?
                    IF ISNULL(This.oLIstPE)
                       This.oLIstPE=CREATEOBJECT("_LIST_PARSER_ENGINE")
                    ENDIF
                    This.oLIstPE.oFTP=This
                    llRet=This.oLIstPE.Parse(@luData,@lcData)
                    This.oLIstPE.oFTP=.NULL.
            ENDCASE
         ENDIF
         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
         RETURN llRet
      ELSE
         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
         RETURN .F.     && Unable to get FTP Connection   
      ENDIF