Class SFtpDir

All Implemented Interfaces:
AutoCloseable

public class SFtpDir extends ChilkatObject
<section class="sftpdir-summary">

Inspect, sort, and iterate an SFTP directory listing.

Chilkat.SFtpDir represents a directory listing returned by an SFTP operation. It provides the original path used to fetch the listing, the number of files and subdirectories found, methods for retrieving filenames or full SFtpFile entry details by index, sorting support, and a way to load a completed asynchronous directory-listing result.

Directory listing object

Holds the files and subdirectories returned from an SFTP directory-read operation.

Original path tracking

Use OriginalPath to see the remote path that was requested when the directory listing was created.

Entry count

Read NumFilesAndDirs to determine how many directory entries are available for iteration.

Filename access

Use GetFilename to retrieve the name of an entry by zero-based index.

Full entry details

Use FileAt to populate an SFtpFile object with metadata for a selected file or subdirectory.

Sorting and async results

Sort entries by filename, timestamps, or size, and load directory listings returned from completed async tasks.

Common pattern: Use a Chilkat.SFtp object to open or read a remote directory, then use the returned SFtpDir object to inspect NumFilesAndDirs, optionally call Sort, and loop from index 0 through the final entry. Use GetFilename when only names are needed, or FileAt when the application needs the full SFtpFile metadata for each entry.

</section>

Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when done; an unclosed instance is freed when it becomes unreachable.

See Also:
Online reference
  • Constructor Details

    • SFtpDir

      public SFtpDir()
      Creates a new SFtpDir object.
  • Method Details

    • getNumFilesAndDirs

      public int getNumFilesAndDirs()
      Returns the number of entries in this directory listing.

      The count includes every item returned by the server, such as regular files, directories, symbolic links, and special entries. Valid zero-based indexes range from 0 through NumFilesAndDirs - 1.

      Returns:
      the value of the NumFilesAndDirs property (read-only)
    • getOriginalPath

      public String getOriginalPath()
      Returns the original remote path used to create this directory listing.

      This is the same path string that was supplied to the SFTP directory-open operation. It identifies the requested directory and is retained with the listing for later reference.

      Returns:
      the value of the OriginalPath property (read-only)
    • fileAt

      public void fileAt​(int index, SFtpFile fileObj)
      Copies the metadata for the directory entry at the zero-based index into fileObj.

      The first entry is at index 0. Use getNumFilesAndDirs() to determine the number of available entries.

      The populated SFtpFile object provides the entry name, type, size, timestamps, ownership, permissions, and any additional attributes supplied by the SFTP server.

      Use getFilename(int) when only the entry name is needed.

      Parameters:
      index - the index argument
      fileObj - the fileObj argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getFilename

      public String getFilename​(int index)
      Returns the filename of the directory entry at the zero-based index.

      The first entry is at index 0. Use getNumFilesAndDirs() to determine the number of available entries.

      Use fileAt(int, SFtpFile) when the application needs the full SFtpFile metadata rather than only the entry name.

      Parameters:
      index - the index argument
      Returns:
      the result (never null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • sort

      public void sort​(String field, boolean ascending)
      Reorders the files and subdirectories in this listing according to field.

      Set ascending to true for ascending order or false for descending order. The new order is used by index-based methods such as getFilename(int) and fileAt(int, SFtpFile).

      field Sort key

      filename Filename using the normal case-sensitive comparison.

      filenameNoCase Filename using a case-insensitive comparison.

      lastModifiedTime Last-modified date and time.

      lastAccessTime Last-access date and time.

      lastCreateTime Creation date and time.

      size Entry size in bytes.

      Parameters:
      field - the field argument (not null)
      ascending - the ascending argument