添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
integer li_err,li_err2
oleobject lo_SessionOptions, lo_Session, lo_remoteDirectoryInfo, lo_TransferOperationResult, lo_TransferOptions,lo_Protocol
    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 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.

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"

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.
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
   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