- John Bailey
- PowerBuilder
- 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.
Find Questions by Tag
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.