GetFTPDirectoryArray Method
Class: FTP_SERVICE
Description:Get a list of files from the current directory on the FTP Server
This method retrieves a list of files from the current directory on the FTP Server. The files are placed in an array with each row being a file and that file's information. The array is created from a variable that is passed by reference to the function. So when the function returns, the Files variable contains an array of files.

Not all the array elements may be filled in, depending on the type operating system the FTP Server is running on. For example, if the FTP Server is running on NT Server, long file names are supported.

=
Object.GetFTPDirectoryArray
Parameter
laDirectory
Array of files
Type Array
By reference  
Direction Output
Holds an array of files after the function completes.
The Files array has the following structure:
TypePositionNameDescription
C[x, 1]File nameLong file name if available
C[x, 2]Alternate File nameShort file name if available
N[x, 3]File SizeSize of file in bytes
T[x, 4]File Create DateFile create date and time
T[x, 5]File Last Access TimeLast access date and time
T[x, 6]File Last Write TimeLast write date and time
C[x, 7]File AttributesFile attributes

The file Attributes array index is a string with the following characters concatenated together:
ValueDescription
'R'FILE_ATTRIBUTE_READONLY
'H'FILE_ATTRIBUTE_HIDDEN
'S'FILE_ATTRIBUTE_SYSTEM
'D'FILE_ATTRIBUTE_DIRECTORY
'A'FILE_ATTRIBUTE_ARCHIVE
'N'FILE_ATTRIBUTE_NORMAL
'T'FILE_ATTRIBUTE_TEMPORARY
'C'FILE_ATTRIBUTE_COMPRESSED
'O'FILE_ATTRIBUTE_OFFLINE
lcMask
Mask files
Type Character
Direction Input
Specifies a file mask to filter files in the operation.
lnFlag
The flags that indicate various options.
Type Numeric
Direction Input
Value is combined with INTERNET_FLAG_RELOAD. Can be one of the following:
ValueDescription
INTERNET_FLAG_HYPERLINKForces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to reload the item from the network.
INTERNET_FLAG_NEED_FILEIdentical to the preferred value, INTERNET_FLAG_MUST_CAHCE_REQUEST. Causes a temporary file to be created if the file cannot be cached.
INTERNET_FLAG_NO_CACHE_WRITEDoes not add the returned entity to the cache.
INTERNET_FLAG_RELOADForces a download of the requested file, object, or directory listing from the origin server, not from the cache.
INTERNET_FLAG_RESYNCHRONIZEReloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP and Gopher resources are reloaded.
Assumed from MSDN.
liCount
The count of rows in output array.
Type Numeric
By reference  
Direction Output
Return value Boolean
Returns .T. if the function successfully returned the current directory on the FTP Server. Returns .F. if the function could not get the current directory.
Remarks
Note
After the function returns, doing an EMPTY(laDirectory) will return .T. if no files were found in the directory on the FTP Server.
Example
LOCAL loFTP,lii LOCAL ARRAY laFolders(1) #INCLUDE "ftp.h" SET PROCEDURE TO ftp.prg ADDITIVE loFTP=CREATEOBJECT('ftp_service') IF loFTP.OpenInternet("ABONNE", "PWD", "10.10.10.10", "21") IF !loFTP.GetFTPDirectoryArray(@laFolders,"*.txt") ?loFTP.GetExtendedErrorCode(),loFTP.GetExtendedErrorMsg() ELSE FOR lii=1 TO ALEN(laFolders,1) ?laFolders[lii, 1] && File name ?CHR(9)+"Alternate File name: "+laFolders[lii, 2] ?CHR(9)+"File Size: "+STR(laFolders[lii, 3],11) ?CHR(9)+"File Create Date: "+TTOC(laFolders[lii, 4]) ?CHR(9)+"File Last Access Time: "+TTOC(laFolders[lii, 5]) ?CHR(9)+"File Last Write Time: "+TTOC(laFolders[lii, 6]) ?CHR(9)+"File Attributes: "+laFolders[lii, 7] NEXT ENDIF =loFTP.CloseInternet() ENDIF RELEASE PROCEDURE ftp.prg
See also
Expand/Collapse source code of procedure GetFTPDirectoryArray Source Code
      LPARAMETERS OUTREF laDirectory, INP lcMask,OPT_INP lnFlag, OUTREF liCount
      LOCAL cStruct, liResult, fResult, lffHandle,lii,lnSize
      IF This.OpenFTPConnection(This.cCurrentDir)     && Open an FTP Handle
         lcMask = m.lcMask + cNULL
              
         * Dimension the array to store the directory
         * [x, 1] = FileName
         * [x, 2] = Alternate FileName
         * [x, 3] = File Size
         * [x, 4] = File Create Date
         * [x, 5] = File Last Access Time
         * [x, 6] = File Last Write Time
         * [x, 7] = File Attributes
         DIMENSION m.laDirectory [1, 7]
         laDirectory [1, 1] = .F.
         lnFlag=BITOR(INTERNET_FLAG_RELOAD,IIF(PCOUNT()<=3,0,m.lnFlag))
         liCount=0
                                    
         * This is for a FoxPro Quirk.
         lcStruct = REPL(CHR(0),319)+CHR(0)   && Allocate space for the returned structure
                  
         =This.BeforeGetFTPDirectoryArray(@m.laDirectory, @m.lcMask,m.lnFlag)
         * Get the first file or find out if 
         lffHandle = FtpFindFirstFile(This.nConnect_Handle, @m.lcMask, @m.lcStruct, m.lnFlag, 0)
         This.GetExtendedError()
                  
         IF m.lffHandle = 0 AND This.nResult_Code <> ERROR_NO_MORE_FILES
            RETURN .F.
         ENDIF

         IF m.lffHandle = 0 AND This.nResult_Code = ERROR_NO_MORE_FILES
            RETURN .T.
         ENDIF

         * Parse out First File Information
         =This.CrackFile(m.lcStruct, @m.laDirectory)
         liCount=1    
         llResult = 1
         DO WHILE This.nResult_Code != ERROR_NO_MORE_FILES AND m.llResult != 0
            lcStruct = SPACE(319)
            * Get next files
            liResult = InternetFindNextFile(m.lffHandle, @m.lcStruct)
            =This.GetExtendedError()
                        
            * If we got good information, go ahead and parse it
            IF This.nResult_Code != ERROR_NO_MORE_FILES AND m.llResult != 0
               liCount=m.liCount+1
               =This.CrackFile(m.lcStruct, @m.laDirectory)
            ENDIF
         ENDDO
         =This.AfterGetFTPDirectoryArray(@m.laDirectory, @m.lcMask, m.lnFlag,m.liResult)
         =InternetCloseHandle(m.lffHandle)

         FOR lii=1 TO ALEN(m.laDirectory,1)
             IF ATC(m.laDirectory(m.lii,7),"D")=0 AND This.GetFileSize(m.laDirectory(m.lii,1),@m.lnSize)
                laDirectory(m.lii,3)=m.lnSize
             ENDIF
         NEXT

         =IIF(This.lMultiOperations,.T.,This.CloseFTPConnection())   && Close FTP Handle
         RETURN .T.
      ELSE
         RETURN .F.     && Unable to get FTP Connection    
      ENDIF