Skip to content

SSH.ListDirectory

Andrew Lambert edited this page Nov 26, 2022 · 3 revisions

SSH.ListDirectory

Method signature

 Protected Function ListDirectory(Optional Session As SSH.Session, URL As String) As SSH.SFTPDirectory

Parameters

Name Type Comment
Session Session Optional. If specified, an active SSH session to use.
URL String The fully qualified URL to list.

Return value

Returns a SFTPDirectory object that you can use to iterate over the directory.

Remarks

This convenience method prepares a directory listing over SFTP. If the Session parameter is specified then only the path part of the URL is used. Raises an exception on error.

Example

This example specifies everything in the URL

  Dim lister As SSH.SFTPDirectory = SSH.ListDirectory("sftp://username:password@ssh.example.com:2222/pub/")
  Dim names() As String
  
  Do
    names.Append(lister.CurrentName)
  Loop Until Not lister.ReadNextEntry()
  
  lister.Close()

This example uses an existing session.

  Dim session As SSH.Session = SSH.Connect("ssh.example.com", 2222, "username", "password")
  Dim lister As SSH.SFTPDirectory = SSH.ListDirectory(session, "/pub/")
  Dim names() As String
  
  Do
    names.Append(lister.CurrentName)
  Loop Until Not lister.ReadNextEntry()
  
  lister.Close()
Clone this wiki locally