Written by

Sr Application Development Analyst at The Ohio State University Wexner Medical Center
Question Scott Roth · Jun 9, 2017

Invoking EnsLib.FTP.OutboundAdpter from Object Script

I have a case where I am creating a PDF file from an Encoded String, and I need to transfer this file over to another server. I was wondering since this is PDF file if I could just invoke the FTP.OutboundAdapter within my Object script that is creating the PDF from the encoded string. Is this possible? Does anyone have an examples of using EnsLib.FTP.OutboundAdpater within their Object Script?

Thanks

Scott Roth

Integration - Interfaces

The Ohio State University Wexner Medical Center

Comments

Scott Roth  Jun 9, 2017 to Eduard Lebedyuk

I took your suggestion about using %Net.FtpSession to transfer the file back and forth between the two boxes, however I am running into an issue trying to ftp.Store the file. Can I have a second pair of eyes take a look at this to see what I am doing wrong?

ClassMethod DecodeBase64HL7ToFileFaxing(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String
{
set ftp=##class(%Net.FtpSession).%New()
if 'ftp.Connect("xxxxx","xxxxx","xxxxxx") $$$LOGINFO("Unable to connect to inteng11") quit
set Oref = ##class(%FileBinaryStream).%New()
set Oref.Filename = FileName
Do base64.Rewind()
While 'base64.AtEnd {
     set ln = base64.ReadLine()
    set lnDecoded = $system.Encryption.Base64Decode(ln)
do Oref.Write(lnDecoded)
}
if 'ftp.SetDirectory("/home/egate/Scott") $$$LOGINFO("Unable to change directory") quit
If 'ftp.Store(Oref,stream) $$$LOGINFO("Unable to write file") quit
if 'ftp.Logout() $$$LOGINFO("Failed to logout") quit
}

Thanks

0
Eduard Lebedyuk  Jun 9, 2017 to Scott Roth

I'd start without base64 decode just to check how ftp works.

I think this would be enough to work (1st argument in Store is a full filename and second is a stream you want to put there):

ClassMethod DecodeBase64HL7ToFileFaxing(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String
{
    set ftp=##class(%Net.FtpSession).%New()
    if 'ftp.Connect("xxxxx","xxxxx","xxxxxx") $$$LOGINFO("Unable to connect to inteng11")
    if 'ftp.Store(FileName, base64) $$$LOGINFO("Unable to write file")
    if 'ftp.Logout() $$$LOGINFO("Failed to logout")
    quit $$$OK
}
0
Scott Roth  Jun 12, 2017 to Eduard Lebedyuk

I was able to figure out what exactly I was doing wrong. Thanks. One last question is it possible to call Ensemble-->Configuration-->Credenitals, into Cache Object Script?

0
Eduard Lebedyuk  Jun 12, 2017 to Scott Roth

To get user/pass? Sure:

set sc = #class(Ens.Config.Credentials).GetCredentialsObj(.cred, "caller.class", "Ens.Config.Credentials", "CredentialsId")
write cred.Username
write cred.PasswordGet()
0