Skip to content

SSH.SFTPDirectory

Andrew Lambert edited this page Nov 6, 2020 · 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 to subdirectories.

Methods

Properties

Example

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

  Dim session As New SSH.Session
  If Not session.Connect("ssh.example.com", 22) Then
    Print("Connection failed.")
    Return 1
  End If
  If Not session.SendCredentials("username", "password") Then
    Print(session.LastErrorMsg)
    session.Close
    Return 1
  End If
  
  Dim sftp As New SSH.SFTPSession(session)
  Dim lister As SSH.SFTPDirectory = sftp.ListDirectory("/path/to/directory/")
  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