SFTP Object
 
Syntax
 
SFTP.OpenDir(path As String) As String
 
Description
Opens a directory for reading. To get a directory listing, first open the directory by calling this method, then call ReadDir to read the directory, and finally call CloseHandle to close the directory.
 
The SFTP protocol represents file names as strings. File names are assumed to use the slash ('/') character as a directory separator.
 
File names 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). Note that identifying the user is assumed to take place outside of this protocol.
 
Servers SHOULD interpret a path name component ".." as referring to the parent directory, and "." as referring to the current directory.
 
An empty path name is valid, and it refers to the user's default directory (usually the user's home directory).
 
Please note: This method does NOT "change" the remote working directory. It is only a method for opening a directory for the purpose of reading the directory listing.
 
SFTP is Secure File Transfer over SSH. It is not the FTP protocol. There is no similarity or relationship between FTP and SFTP. Therefore, concepts such as "current remote directory" that exist in FTP do not exist with SFTP. With the SFTP protocol, the current directory will always be the home directory of the user account used during SSH/SFTP authentication. You may pass relative or absolute directory/file paths. A relative path is always relative to the home directory of the SSH user account.
 
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