FtpClient.GetNameListing Method (String)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Returns a file/directory listing using the NLST command.

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

Syntax

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

Parameters

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

Return Value

Type: array<String>[]()[][]
A string array of file and directory names if any were returned.

Implements

IFtpClient..::..GetNameListing(String)

Examples

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

namespace Examples {
    class GetNameListingExample {
        public static void GetNameListing() {
            using (FtpClient cl = new FtpClient()) {
                cl.Credentials = new NetworkCredential("ftp", "ftp");
                cl.Host = "ftp.example.com";
                cl.Connect();

                foreach (string s in cl.GetNameListing()) {
                    // load some information about the object
                    // returned from the listing...
                    bool isDirectory = cl.DirectoryExists(s);
                    DateTime modify = cl.GetModifiedTime(s);
                    long size = isDirectory ? 0 : cl.GetFileSize(s);


                }
            }
        }
    }
}

See Also