Retrieving a remote directory listing |
Getting a directory listing as a String
To get a directory listing returned as a string you may use the GetDirListingAsString method.
Example
[C#]
// get listing of current remote directory as a string
String dirListing = myFtp.GetDirListingAsString(".");
[Visual Basic]
' get listing of current remote directory as a string
Dim dirListing As String = myFtp.GetDirListingAsString("*.*")
Getting a directory listing as an Enumeration
In some cases you will want to evaluate the entries returned in a directory listing. In this case you will want to use the GetDirListing method. This method returns an numeration of FtpFile. Each FtpFile instance represents a read-only entry in the directory listing and may be queried for additional information.
Example
[C#]
// get directory listing
IEnumerator e = myFtp.GetDirListing();
// enumerate thru listing printing filename for each entry
while (e.MoveNext()) {
FtpFile file = (FtpFile)e.Current;
Console.WriteLine("Filename: " + file.Filename);
}
[Visual Basic]
' get directory listing
Dim e As IEnumerator = myFtp.GetDirListing()
' enumerate thru listing printing filename for each entry
While e.MoveNext()
Dim file As FtpFile = e.Current
System.Console.WriteLine("Filename: " + file.Filename)
End While
See also