NLST Method
Class: FTP_SERVICE
Description:Get a list of files and folders from the current directory on the FTP Server
Get simple list of folders and files.
=
Object.NLST
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 cell of array contain a one file or folder name.
Parsing to array do after calling event FTP_SERVICE::AfterNLST().
lcMask
Mask for selecting folders and files
Type Character
Direction Input
liFlags
Mode flags
Type Boolean
Direction Input
Optional  
This parameter define type of first parameter luData. List of types
ValueDescription
_FTPS_RWF_FileluData is file name.
_FTPS_RWF_StringluData is string.
_FTPS_RWF_ArrayluData 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_ASCIITransfers the file as ASCII.
FTP_TRANSFER_TYPE_BINARYTransfers 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.NLST("c:\nlstx.txt","",_FTPS_RWF_File,0) MODI FILE "c:\nlst.txt" NOWAIT * Get "Name list" and return it as string =loFTP.NLST(@lcPom,"",_FTPS_RWF_String,0) ?lcPom * Get "Name list" and save it to array ?loFTP.NLST(@laFiles,"download",_FTPS_RWF_Array,0) * For each file get other informations FOR lii=1 to ALEN(lafiles) loFTP.GetFTPDirectoryArray(@laFile, laFiles(lii),0) ? ?laFile[1,1] ?laFile[1, 2] ?laFile[1, 3] ?laFile[1, 4] ?laFile[1, 5] ?laFile[1, 6] ?laFile[1, 7] NEXT =loFTP.CloseInternet() ENDIF RELEASE PROCEDURE ftp.prg DEFINE CLASS _myFTP AS FTP_SERVICE PROCEDURE BeforeNLST(luData,lcMask,liFlags,lnFlag) ?PROGRAM(16) ?CHR(9),luData,lcMask,liFlags,lnFlag ENDPROC PROCEDURE AfterNLST(luData,lcMask,liFlags,lnFlag,liResult) ?PROGRAM(16) ?CHR(9),luData,lcMask,liFlags,lnFlag,liResult ENDPROC PROCEDURE AtNLST(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 NLST 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,m.liFlags)
      lnFlag=IIF(PCOUNT()<4,FTP_TRANSFER_TYPE_ASCII,m.lnFlag)

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

         This.BeforeNLST(@m.luData,@m.lcMask,m.liFlags,m.lnFlag)

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

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

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

            DO CASE
               CASE m.liResult=0

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

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

               CASE BITTEST(m.liFlags,2) && Array?
                    * parse data by CRLF
                    IF AT("\015\012",m.lcData)>0 && EPLF
                       lcData=STRTRAN(m.lcData,"\015\012",CRLF)
                    ENDIF
                    IF VAL(STRTRAN(SUBS(VERSION(),LEN("Visual FoxPro ")+1,2),"0",""))>=6
                       liCount=ALINES(m.luData,m.lcData)
                    ELSE
                       liCount=OCCURS(CRLF,m.lcData)
                       IF m.liCount>0 THEN
                          DIME luData[m.liCount, 1]
                          lii=1  
                          liEnd=AT(CRLF,m.lcData,1)
                          DO WHILE m.liEnd>0
                             luData[m.lii, 1]=LEFT(m.lcData,m.liEnd-1)
                             lcData=SUBSTR(m.lcData,m.liEnd+2)
                             liEnd=AT(CRLF,m.lcData,1)
                             lii=m.lii+1  
                          ENDDO
                       ENDIF
                    ENDIF
            ENDCASE
         ENDIF
         This.AfterNLST(m.luData,m.lcMask,m.liFlags,m.lnFlag,m.liResult)
         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
         RETURN m.llRet
      ELSE
         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
         RETURN .F.     && Unable to get FTP Connection   
      ENDIF