Skip to content

SSH.SFTPDirectory

Andrew Lambert edited this page Jun 15, 2021 · 23 revisions

SSH.SFTPDirectory

Class Declaration

 Protected Class SFTPDirectory

Remarks

This class represents a directory listing operation over SFTP.

Create a new instance and then read the CurrentName, CurrentType, CurrentLength, etc. properties to get metadata on the current item in the listing, then call ReadNextEntry() to load the next item.

If the SuppressVirtualEntries property is set to True and the directory is empty then the CurrentType property will be SFTPEntryType.Unknown and the CurrentIndex property will be -1. If SuppressVirtualEntries is False then an empty directory will appear to contain two subdirectories.

Methods

Properties

Example

This example is a console application that prints a file listing for a remote directory.

  Dim session As SSH.Session = SSH.Connect("ssh.example.com", 22, "username", "password")
  If Not session.IsAuthenticated Then
    Print(session.LastErrorMsg)
    session.Close
    Return
  End If
  
  Dim sftp As New SSH.SFTPSession(session)
  Dim lister As SSH.SFTPDirectory = sftp.ListDirectory("/path/to/directory/")
  If lister = Nil Then
    Print(sftp.LastStatusName) ' not found, etc.
    sftp.Close
    session.Close
    Return
  End If

  Do
    If lister.CurrentType = SSH.SFTPEntryType.File Then
      Print(lister.CurrentName + " (" + Str(lister.CurrentLength) + " bytes)")
    Else
      Print(lister.CurrentName + " (DIR)")
    End If
  Loop Until Not lister.ReadNextEntry()

See also

Clone this wiki locally