Asking for help!! Open connection via WinSCP in Powerbuilder10.

Advertisement

tiver109
Joined:
Posts:
4
Location:
Taiwan

Asking for help!! Open connection via WinSCP in Powerbuilder10.

HI everyone, I get some problem when I'm trying to open a ftp connection via WinSCP in Powerbuilder10. Hope that someone can help me. Orz

This is my Code :

integer li_err,li_err2
oleobject lo_SessionOptions, lo_Session, lo_remoteDirectoryInfo, lo_TransferOperationResult, lo_TransferOptions,lo_Protocol

TRY
    lo_SessionOptions = create oleobject
    li_err = lo_SessionOptions.connecttonewobject("WinSCP.SessionOptions")

    lo_sessionOptions.Protocol = 2
    lo_SessionOptions.HostName = "192.168.1.50"
    lo_SessionOptions.UserName = "ftp_user"
    lo_SessionOptions.Password = "123456"
    lo_SessionOptions.PortNumber = 21
    lo_SessionOptions.FtpMode = 0

    lo_Session = create oleobject
    li_err2 = lo_Session.connecttonewobject("WinSCP.Session")

    if lo_Session.Opened then
   lo_Session.Abort()
    end if

   lo_Session.Open(lo_SessionOptions)
CATCH (OLERuntimeError exRuntime)
    messagebox("error",string(exRuntime))
END TRY

There are two problem that I've got.

First is the propertise of SessionOptions Protocol. I know that document say that the value will be something like Protocol.Sftp or Protocol.ftp. but I can't make powerbuilder recognize type protocol, so I set it to integer value 2(
assuming it's start from 0). How can i set this propertise?

Second is I get the error when running open method. The error just says "Error calling external object function open at line xx in clicked event .....", and OLERuntimeError exRuntime is always null.

p.s I've already Registry the dll. the li_err when connecttonewobject is 0.
Can anyone help me? Thanks a lot!!

tiver109, 20180604

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

Re: Asking for help!! Open connection via WinSCP in Powerbuilder10.

I have no experience with PowerBuilder.
But do try setting lo_Session.SesisionLogPath = "C:\some\path\session.log"
And inspect the log file, or attach it here.

Reply with quote

tiver109
Joined:
Posts:
4
Location:
Taiwan

Re: Asking for help!! Open connection via WinSCP in Powerbuilder10.

martin wrote:

I have no experience with PowerBuilder.
But do try setting lo_Session.SesisionLogPath = "C:\some\path\session.log"
And inspect the log file, or attach it here.

Hi, Martin
Thanks for your reply !
I've set the SesisionLogPath, but it's didn't generat anything.
And I try to create a .log file before i excute the program. The .log file still be empty.

This is how I set :
lo_Session.SessionLogPath = "C:\winscp\session.log"

Reply with quote

martin
Site Admin
martin avatar

Re: Asking for help!! Open connection via WinSCP in Powerbuilder10.

Sorry, we cannot help you with PowerBuilder.

Reply with quote

Advertisement

tiver109
Joined:
Posts:
4
Location:
Taiwan

Re: WinSCP and Powerbuilder

tibor84 wrote:

hi tiver109,
did you succed? i am solving similar problem like you.

Sadly, I did't success, so i tried another way, using Microsoft Winnet.dll without SSH.

Reply with quote

tiver109
Joined:
Posts:
4
Location:
Taiwan

Re: Asking for help!! Open connection via WinSCP in Powerbuilder10.

martin wrote:

Sorry, we cannot help you with PowerBuilder.

It's okay, thanks for you reply.

Reply with quote

tibor84
Joined:
Posts:
2
Location:
Slovakia

Re: WinSCP and Powerbuilder

tiver109 wrote:

tibor84 wrote:

hi tiver109,
did you succed? i am solving similar problem like you.

Sadly, I did't success, so i tried another way, using Microsoft Winnet.dll without SSH.

Hi,
I succeed with this in powerbuilder:
0. Install & register WinSCP dll, so you can see it in powebuilder components in active x part
1. i create new standard with Type oleobject
(File -> New -> PBObject -> Standard class -> oleobject
2. Save as n_myole, and add this source to externalexception
messagebox("External Error", string(resultcode) + ": " + description)
3. Sample source:
n_myole s_ftp // for WinSCP.Session
n_myole s_opt // for WinSCP.sessionoptions
n_myole s_trans // for WinSCP.TransferOptions, i just used default values (Binary transfer and overwrite options)
int return_code

s_ftp = CREATE n_myole

return_code = s_ftp.connecttonewobject("WinSCP.Session")

if return_code <> 0 then
   messagebox("Error", "S_FTP Component installation error")
   return - 1
end if   

s_opt = CREATE n_myole   
return_code = s_opt.connecttonewobject("WinSCP.sessionoptions")

if return_code <> 0 then
   messagebox("Error", "Seasion Options  Component installation error")
   return - 1
end if      

s_trans = CREATE n_myole      
return_code = s_trans.connecttonewobject("WinSCP.TransferOptions")

if return_code <> 0 then
   messagebox("Error", "Transfer Options Component installation error")
   return - 1
end if      

s_opt.protocol = 0 // SFTP - i couldn't use WinSCP constans
s_opt.hostname = i_server_ip // server IP
s_opt.UserName = i_user_name // user id
s_opt.Password = i_user_pass // user pass
s_opt.GiveUpSecurityAndAcceptAnySshHostKey = true  // this is not save, instead server key should be used

try
   any result
   result = s_ftp.open(s_opt) 
   return  integer(result)
catch (runtimeerror  e)
  messagebox("Error",e.getMessage())
return -1
end try

Ll_rtn = integer (s_ftp.putfiles(source_file, target_file, false,s_trans ) )

IF Ll_rtn < 0 THEN
   as_msg   =   "File Upload Error(FTP)!"
END IF

s_ftp.close()

I don't know how to use winscp constans for setup details. If somebody could just paste value for each options like:
binnary = 0

overwrite = 0

Edit1:
i created my custom object to catch winscp errors

Reply with quote

Advertisement

You can post new topics in this forum