Retrieving a remote directory listing |
There are two ways that you can retrieve a directory listing from the server. The method used will depend on largely how you want to process the results.
Getting a directory listing as a string
To get a directory listing returned as a string you may use the Sftp.GetDirListingAsString method.
Example
[C#]
// get directory listing to console
Console.WriteLine(sftp.GetDirListingAsString());
[VB]
' get directory listing to console
Console.WriteLine(sftp.GetDirListingAsString())
Parsing entries in a directory listing
In some cases you will want to evaluate the entries returned in a directory listing. In this case you will want to use the Sftp.GetDirListing method. This method returns a System.Collections.IEnumerator of Jscape.Sftp.Packets.FileInfo. Each FileInfo instance represents a read-only entry in the directory listing and may be queried for additional information.
Example
[C#]
// get directory listing as enumeration
IEnumerator results = sftp.GetDirListing();
// enumerate thru items printing filename for each
while(results.MoveNext()) {
// get next item casting to FileInfo
Jscape.Sftp.Packets.FileInfo file = (Jscape.Sftp.Packets.FileInfo)results.Current;
Console.WriteLine(file.Name);
}
[VB]
' get directory listing as enumeration
Dim results As IEnumerator = sftp.GetDirListing
' enumerate thru items printing filename for each
While results.MoveNext
Dim file As Jscape.Sftp.Packets.FileInfo = CType(results.Current, Jscape.Sftp.Packets.FileInfo)
Console.WriteLine(file.Name)
End While