IPWorks SSH 2020 macOS Edition

Questions / Feedback?

ListDirectory Method

List the current directory specified by RemotePath on an server using SFTP.

Syntax

public func listDirectory() throws -> String

Remarks

This method lists the directory specified by RemotePath. RemoteFile may also be set to a filemask to list associated files. The file listing is received through the DirList event.

This method returns an Operation Id which identifies the operation in progress. A corresponding SSHPlexOperation will also be added to the Operations collection. The operation can be canceled by passing the Operation Id to the CancelOperation method.

When the operation completes the ListDirectoryComplete event will fire, and the SSHPlexOperation associated with the completed operation will be removed from the Operations collection. Inspect the parameters of the ListDirectoryComplete event to determine the result.

If there is no SSH session in place, one is automatically created by the component first.

This method is only applicable when ChannelType is set to cstSftp.

The directory entries are provided through the DirList event and also via the DirList* properties.

SSHPlexControl.RemoteFile = ""; //Clear filemask
SSHPlexControl.RemotePath = "MyFolder";
string opId = SSHPlexControl.ListDirectory();
// ListDirectory operates async so we must wait for it to finish
while (SSHPlexControl.Operations.Keys.Contains(opId)) {
    SSHPlexControl.DoEvents();
}
for (int i = 0; i < SSHPlexControl.DirList.Count; i++)
{
  Console.WriteLine(SSHPlexControl.DirList[i].FileName);
  Console.WriteLine(SSHPlexControl.DirList[i].FileSize);
  Console.WriteLine(SSHPlexControl.DirList[i].FileTime);
  Console.WriteLine(SSHPlexControl.DirList[i].IsDir);
}

The RemoteFile property may also be used as a filemask when listing files. For instance:

SSHPlexControl.RemoteFile = "*.txt";
SSHPlexControl.ListDirectory();

Note: Since RemoteFile is used as a filemask be sure to clear or reset this value before calling ListDirectory

Copyright (c) 2023 /n software inc. - All rights reserved.
IPWorks SSH 2020 macOS Edition - Version 20.0 [Build 8501]