SFTP Object
 
Syntax
 
SFTP.ReadDir(handle As String) As ChilkatSFtpDir
 
Description
Reads the contents of a directory and returns the directory listing (as an object). The handle returned by OpenDir should be passed to this method.
 
Returns Nothing on failure
 
See Also

Example
Sub Main
 
' Set some timeouts, in milliseconds:
sftp.ConnectTimeoutMs = 5000
sftp.IdleTimeoutMs = 10000
 
' Connect to the SSH server. 
' The standard SSH port = 22
' The hostname may be a hostname or IP address.
Dim hostname As String
hostname = "www.my-sftp-server.com"
Dim port As Long
port = 22
Dim success As Long
success = sftp.Connect(hostname,port)
If (success <> 1) Then
    Debug.Print sftp.LastErrorText
    Exit Sub
End If
 
' Authenticate with the SSH server.  Chilkat SFTP supports
' both password-based authenication as well as public-key
' authentication.  This example uses password authenication.
success = sftp.AuthenticatePw("myLogin","myPassword")
If (success <> 1) Then
    Debug.Print sftp.LastErrorText
    Exit Sub
End If
 
' After authenticating, the SFTP subsystem must be initialized:
success = sftp.InitializeSftp()
If (success <> 1) Then
    Debug.Print sftp.LastErrorText
    Exit Sub
End If
 
' Open a directory on the server...
' Paths starting with a slash are "absolute", and are relative
' to the root of the file system. Names starting with any other
' character are relative to the user's default directory (home directory).
' A path component of ".." refers to the parent directory,
' and "." refers to the current directory.
Dim handle As String
handle = sftp.OpenDir(".")
If (sftp.LastMethodSuccess <> 1) Then
    Debug.Print sftp.LastErrorText
    Exit Sub
End If
 
' Download the directory listing:
Dim dirListing As ChilkatSFtpDir
Set dirListing = sftp.ReadDir(handle)
If (sftp.LastMethodSuccess <> 1) Then
    Debug.Print sftp.LastErrorText
    Exit Sub
End If
 
' Iterate over the files.
Dim i As Long
i = 0
Dim n As Long
n = dirListing.NumFilesAndDirs
Do While i < n
    Dim fileObj As ChilkatSFtpFile
    Set fileObj = dirListing.GetFileObject(i)
 
    Debug.Print fileObj.Filename
    Debug.Print fileObj.FileType
    Debug.Print "Size in bytes: " & fileObj.Size32
    Debug.Print "----"
 
    i = i + 1
Loop
 
' Close the directory
success = sftp.CloseHandle(handle)
If (success <> 1) Then
    Debug.Print sftp.LastErrorText
    Exit Sub
End If
 
Debug.Print "Success."
 
End Sub