GetFileList Method  

Return an unparsed list of files in the specified directory.


object.GetFileList( RemotePath, Buffer, [Length], [Options] )


A string which specifies the name of a directory on the server. The list of files and subdirectories in that directory will be returned to the client. To obtain a list of files in the current working directory on the server, use an empty string.
A buffer that the data will be stored in. It is recommend that a String variable type is used, although it is also possible to provide a Byte array as this argument, in which case the file listing will converted to ANSI characters and fill the array. Any other variable type will cause this method to throw an exception.
A numeric value which specifies the maximum number of characters to read. If the argument is omitted, then the maximum size of the buffer will be calculated automatically. In most cases, it is not necessary to provide this argument.
A numeric value which specifies how the list of files should be returned by the server. It may be one of the following values:
Value Constant Description
0 ftpListDefault This option specifies the server should return a complete file list, providing all of the information available about that file. This typically includes the date and time the file was last modified, the size of the file and access rights. This option is the default, and will be used if the argument is omitted from the method call.
1 ftpListNameOnly This option specifies the server should only return a list of file names, with no additional information. This option may be used if the server returns the file listing in a format that is not recognized by the control.

Return Value

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.


The GetFileList method returns a list of files in the specified directory, copying the data to a string buffer. Unlike the ReadDirectory method that parses a directory listing, this method returns the unparsed file list data. The actual format of the data that is returned depends on the operating system and how the server implements file listings. For example, UNIX servers typically return the output from the /bin/ls command.

Some servers may not support file listings for any directory other than the current working directory. If an error is returned when specifying a directory name, try changing the current working directory using the ChangeDirectory method and then call this method again, an empty string as the RemotePath parameter.

This method can be particularly useful when the client is connected to a server that returns file listings in a format that is not recognized by the control. The application can retrieve the unparsed file listing from the server and parse the contents. Note that if you specify the ftpListNameOnly option, the data will only contain a list of file names and there will be no way for the application to know if they represent a regular file or a subdirectory.

This method is supported for both FTP and SFTP (SSH) connections, however the format of the data may differ depending on which protocol is used. Most UNIX based FTP servers will not list files and subdirectories that begin with a period, however most SFTP servers will return a list of all files, even those that begin with a period.

This method will cause the current thread to block until the file listing completes, a timeout occurs or the operation is canceled.

See Also

ChangeDirectory Method, OpenDirectory Method, ReadDirectory Method