Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) SFTP Read Directory ListingDemonstrates how to download a directory listing and iterate over the files.
integer li_rc oleobject loo_Sftp string ls_Hostname integer li_Port integer li_Success string ls_Handle oleobject loo_DirListing integer i integer n oleobject loo_FileObj // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Important: It is helpful to send the contents of the // sftp.LastErrorText property when requesting support. loo_Sftp = create oleobject // Use "Chilkat_9_5_0.SFtp" for versions of Chilkat < 10.0.0 li_rc = loo_Sftp.ConnectToNewObject("Chilkat.SFtp") if li_rc < 0 then destroy loo_Sftp MessageBox("Error","Connecting to COM object failed") return end if // Set some timeouts, in milliseconds: loo_Sftp.ConnectTimeoutMs = 5000 loo_Sftp.IdleTimeoutMs = 10000 // Connect to the SSH server. // The standard SSH port = 22 // The hostname may be a hostname or IP address. ls_Hostname = "www.my-sftp-server.com" li_Port = 22 li_Success = loo_Sftp.Connect(ls_Hostname,li_Port) if li_Success <> 1 then Write-Debug loo_Sftp.LastErrorText destroy loo_Sftp return 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. li_Success = loo_Sftp.AuthenticatePw("myLogin","myPassword") if li_Success <> 1 then Write-Debug loo_Sftp.LastErrorText destroy loo_Sftp return end if // After authenticating, the SFTP subsystem must be initialized: li_Success = loo_Sftp.InitializeSftp() if li_Success <> 1 then Write-Debug loo_Sftp.LastErrorText destroy loo_Sftp return 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. ls_Handle = loo_Sftp.OpenDir(".") if loo_Sftp.LastMethodSuccess <> 1 then Write-Debug loo_Sftp.LastErrorText destroy loo_Sftp return end if // Download the directory listing: loo_DirListing = loo_Sftp.ReadDir(ls_Handle) if loo_Sftp.LastMethodSuccess <> 1 then Write-Debug loo_Sftp.LastErrorText destroy loo_Sftp return end if // Close the handle for the directory listing. li_Success = loo_Sftp.CloseHandle(ls_Handle) if li_Success <> 1 then Write-Debug loo_Sftp.LastErrorText destroy loo_Sftp return end if // Iterate over the files. i = 0 n = loo_DirListing.NumFilesAndDirs do while i < n loo_FileObj = loo_DirListing.GetFileObject(i) Write-Debug loo_FileObj.Filename Write-Debug loo_FileObj.FileType Write-Debug "Size in bytes: " + string(loo_FileObj.Size32) Write-Debug "----" destroy loo_FileObj i = i + 1 loop destroy loo_DirListing Write-Debug "Success." destroy loo_Sftp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.