FtpClient.GetListing Method (String)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Gets a file listing from the server. Each FtpListItem object returned contains information about the file that was able to be retrieved. If a DateTime property is equal to DateTime.MinValue then it means the date in question was not able to be retrieved. If the Size property is equal to 0 then it means the size of the object could also not be retrieved.

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public FtpListItem[] GetListing(
	string path
)
Visual Basic
Public Function GetListing ( 
	path As String
) As FtpListItem()
Visual C++
public:
virtual array<FtpListItem^>^ GetListing(
	String^ path
) sealed

Parameters

path
Type: System..::..String
The path of the directory to list

Return Value

Type: array<FtpListItem>[]()[][]
An array of FtpListItem objects

Implements

IFtpClient..::..GetListing(String)

Examples

C#  Copy imageCopy
using System;
using System.Net;
using System.Net.FtpClient;

namespace Examples {
    static class GetListingExample {
        public static void GetListing() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");

                foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                    FtpListOption.Modify | FtpListOption.Size)) {

                    switch (item.Type) {
                        case FtpFileSystemObjectType.Directory:
                            break;
                        case FtpFileSystemObjectType.File:
                            break;
                        case FtpFileSystemObjectType.Link:
                            // derefernece symbolic links
                            if (item.LinkTarget != null) {
                                // see the DereferenceLink() example
                                // for more details about resolving links.
                                item.LinkObject = conn.DereferenceLink(item);

                                if (item.LinkObject != null) {
                                    // switch (item.LinkObject.Type)...
                                }
                            }
                            break;
                    }
                }

                // same example except automatically dereference symbolic links.
                // see the DereferenceLink() example for more details about resolving links.
                foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(),
                    FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks)) {

                    switch (item.Type) {
                        case FtpFileSystemObjectType.Directory:
                            break;
                        case FtpFileSystemObjectType.File:
                            break;
                        case FtpFileSystemObjectType.Link:
                            if (item.LinkObject != null) {
                                // switch (item.LinkObject.Type)...
                            }
                            break;
                    }
                }
            }
        }
    }
}

See Also