1. John Bailey
  2. PowerBuilder
  3. Friday, 8 June 2018 05:56 PM UTC

Replacing FTP with WINSCP to perform SFTP from my application, and I am having trouble decoding (cycling thru) the result set from
"ListDirectory". The winscp examples use syntax like --  (foreach $fileinfo in $files) ... great - doesn't work in PB.

I have all the other functions of winscp that I need working from within my PB App - I can connect to the server, upload/download,
determine file existence, and get file details for a specified file or folder. However List Directory returns a collection and I can't extract
the list of files. I can get the number of files/folders in the collection, but not file info in the collection.

My PB Code (lines 1-40 for demonstration work):

01 oleobject i_winscp_ftp
02 i_winscp_ftp = create oleobject
03 l_rc = i_winscp_ftp.ConnectToNewObject("WinSCP.Session")

04 oleobject i_SessionOptions
05 i_SessionOptions = create oleobject
06 l_rc = i_SessionOptions.ConnectToNewObject("WinSCP.SessionOptions")

07 oleobject o_FileInfo
08 o_FileInfo = create oleobject // "WinSCP.RemoteFileInfo"

09 i_sessionOptions.Protocol = 0 // use SFTP
10 i_SessionOptions.HostName = as_server
11 i_SessionOptions.UserName = as_user
12 i_SessionOptions.Password = as_pwd
13 i_SessionOptions.SshHostKeyFingerprint = as_server_finger

14   // CONNECT using session options ..
15 i_winscp_ftp.Open(i_SessionOptions)

16 // demo - get file info about a specified file/folder ..
17 boolean lb_file_exists
18 lb_file_exists = i_winscp_ftp.FileExists(as_filefldr)
19 if lb_file_exists then
20 // if specified file or folder exists, get info
21   o_FileInfo = i_winscp_ftp.GetFileInfo(ls_filefldr)

22   string ls_name
23   ls_name = o_FileInfo.FullName
    
24   long ln_len
25   ln_len = o_FileInfo.Length
    
26   DateTime ld_date
27   ld_date = o_FileInfo.LastWriteTime

28   character lc_type ; long ll_type // ascii of type character code
29   ll_type = o_FileInfo.FileType
30   lc_type = char(ll_type)
31     // case '-' = 'Regular File' ; case 'D' = 'Directory' ; case 'L' = 'Symbolic Link'
                
32    MessageBox('getfileinfo' , &
33     ls_name + '~r~n Len=' + string(ln_len) + ' date=' + string(ld_date) + ' type= ' + lc_type )
34
35 end if // -- end line 19 lb_file_exists
36
37 oleobject o_RemoteDirInfo  // Session.ListDirectory return class
38 o_RemoteDirInfo = create oleobject
39
40 try
41   o_remotedirinfo = i_winscp_ftp.ListDirectory(ls_remote_dir);
42   string ls_objname
43   ls_objname = o_remotedirinfo.tostring() // RemoteFileInfoCollection
44   long ll_filecount
45   ll_filecount = o_remotedirinfo.Files.Count; // this value correct
46   MessageBox('List Directory', ls_objname + '~r~n Knt1= ' + string(ll_filecount) )

//   can not get each file info class out of collection ..
//
// winscp example shows -- foreach (RemoteFileInfo fileInfo in directory.Files)
// How to get that in PowerBuilder ??
//
// -- ElementAt method listed in ICollection class definition.
// -- could be used to loop thru all records (have filecount),
// -- call compiles but does not run. Maybe syntax issue?

47   o_FileInfo = o_remotedirinfo.Files.ElementAt(0) // 0..n-1 -- ERRORS
48   MessageBox('List Direcotry File Info', o_FileInfo.ToString() )
49
50 catch (throwable exc1)
51     MessageBox("winscp client Try-Catch error", exc1.text)
52 end try

Any help appreciated.

Thanks.

 


Responses (5)
  1. Likes
  2. Latest
  3. Oldest
Loading...

Find Questions by Tag

.EXE .NET 6.0 .NET Assembly .NET Core 3.1 .NET Core Framework .NET DataStore .NET Std Framework 32-bit 64-bit ADO.NET AEM AI Algorithm Amazon AWS Android Apache API APK App Store App Store (Apple) Appeon Workspace Appeon Xcelerator Plug-in Architecture Array ASE Asynchronous Methods Authentication AutoBuild AutoCompiler Automated Testing Automation AutoScript Azure Barcode Base64 Batch BigData BLOB Branch & Merge Browser Bug Build Button C# C# Class Importer C# Editor C# Model generator Calendar Camera Certificate Chrome Citrix Class Client Client/Server Cloud Cluster Collection COM Command Line Compiler Compression Computed Field Configuration Controls Cookies Cordova Crash Cross-Platform Crosstab CSharpAssembly CSharpObject CSS CSV Cursor Data Database Database Driver Database Painter Database Profile Database Provider DataObject DataSource DataStore DataStore (C#) DataStore (PS) DataType DataWindow DATE DATETIME DB2 Debug Debugger Debugging Deployment Design DLL DO-WHILE Dockable Docker Documentation DOUBLE Download DragDrop Edge Edit Style Editor Elevate Conference Email Embedded SQL Emulator Encoding Encryption Enhancement Request Entity Entity Framework ERP Error Event Event Handler Event Handling Excel Exception Export Expression External Functions F# Field File File Access Filter Firefox Firewall Font FOR-NEXT Foreground Format Function Garbage Collection GeoLocation Git Graph HANA Hash Header HTML/5 HTTP/S HTTPClient Icon IDE Identity IIS IMAPI Import InfoMaker Inheritance Installation Integer IntelliSense Interface Internet Internet Explorer iOS IPA iPad iPhone IWA J# Java JavaScript JBoss JDBC JOIN JSON JSONGenerator JSONParser Kestrel Label Lambda Large File LDAP Library License LINQ Linux OS Load Balancing Localization Localized PBVM Log In Log Out Logging LONG LONGLONG macOS MAPI Maps MDI Memory Memory Leak Menu Merge MessageBox Messagging Method Migration MIME TYPE Mobile Model ModelStore ModelStore (C#) MSOLEDBSQL Multi Threading MVC MySQL n-Tier Namespace NativePDF NVO OAuth ODATA ODBC Office Offline OLE OLEDB Online Open Source OpenAPI OpenSSL Oracle OrcaScript Other Outlook Output Package Parameter Patch PayPal PB Classic PB Native PB.NET PBC PBD PBDOM PBG PBJVM PBL PBNI PBORCA PBVM PBX PDF Performance Permission PFC Picture Pipeline Play Store (Google) Plugin Popup Port POST PostgreSQL PowerBuilder PowerBuilder (Appeon) PowerBuilder (SAP) PowerBuilder Compiler PowerBuilder Runtime PowerClient PowerScript (PS) PowerScript IDE PowerScript Migrator PowerServer PowerServer Mobile PowerServer Toolkit PowerServer Web PowerServerLabel Print Properties Proxy Publish PULL PUSH Query Regression Release Renew Resize Response REST Retrieve RibbonBar RibbonBar Builder Rich Text Roadmap RPC Runtime Packager SaaS Scaffolding Script SDI SDK Security Server Service Session Single Sign-on Size SMTP SMTPClient SnapDevelop SOAP Sort Source Code Speech Recognition SQL SQL Anywhere SQL Server SqlBuilder SqlExecutor SQLite SqlModelMapper Storage Stored Procedure Subscription SVN Swagger Syntax TabbedBar TabbedView Tablet TabPage Target TE Control Testing Text TFS Theme TIME Timer TLS/SSL Tomcat TortoiseGit TortoiseSVN Transaction Transparency Trial Trigger TRY-CATCH TX Control Type UI ULONG UltraLite Uninstall Unit Test Unit Testing UNIX OS Update Upgrade Upload URL User Center User Object UWP Validation VARCHAR Variable Versioning Visual Studio Visual Studio Code VM Voice Warning WCF Web API Web Extensions Web Service WebBrowser WebForms WebLogic WebSphere WildFly WinAPI Window Windows OS WinForms Wizard Workgroup Workspace WPF XCODE XHTML XML Zoom

Helpful?

If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.