Question
· Jul 4

Recommended way to read 𝗦𝗙𝗧𝗣 𝗼𝗿 𝗙𝗧𝗣 files

Hello,

First of all thanks for your time reading this question, and thank you for your help.

🎯 We would need to create an Ensemble HealthShare Operation to read files from a FTP / SFTP server.

We have coded:

Class Operaciones.FTP.ConsultaPDFv01r001 Extends Ens.BusinessOperation [ ProcedureBlock ]
{

Parameter ADAPTER = "EnsLib.FTP.InboundAdapter";

Method ConsultarDocumentoPDF(pRequest As Mensajes.Request.ConsultaPDFRequestv01r00, Output pResponse As Mensajes.Response.RecuperarDocumentoPDFv01r00) As %Library.Status
{
	set ftp = ##class(%Net.FtpSession).%New()
	
	set isConnected =  ftp.Connect(..Adapter.FTPServer, ..Adapter.Credentials.Username, ..Adapter.Credentials.Password, ..Adapter.FTPPort) {
	
	$$$LOGINFO($System.Status.GetErrorText(isConnected))
	$$$LOGINFO(isConnected)
	
	if isConnected {
		$$$LOGINFO("HOLA")
		do ftp.SetDirectory(..Adapter.FilePath)
		set stream=##class(%GlobalCharacterStream).%New()
		;set tsC = ftp.Retrieve(pRequest.nombreDocumento, .stream)
		;if 'tsC { $$$LOGERROR("Error al recuperar el documento") }
		if 'ftp.Retrieve(pRequest.nombreDocumento, .stream) { $$$LOGERROR("Error al recuperar el documento") }
		else{
			$$$LOGINFO(stream.Read())
		}
	}
	Quit $$$OK
}

XData MessageMap
{
<MapItems>
	<MapItem MessageType="Mensajes.Request.ConsultaPDFRequestv01r00">
	     <Method>ConsultarDocumentoPDF</Method>
	</MapItem>
</MapItems>
}

}

When we try this operation from the Web Portal, we always get the following result:

First loginfo outputs: "ERROR #00: (sin descripción de error) [no error description]"

Second loginfo shows: 0

 

We have verified that the IP and Port of the server are correct, but we do not understand why it does not connect.

We know that the code does not enter inside the if which checks if it isConnected

set isConnected =  ftp.Connect(..Adapter.FTPServer, ..Adapter.Credentials.Username, ..Adapter.Credentials.Password, ..Adapter.FTPPort) {

if isConnected {

 

How could we get what exact error is happening?

 
🔎 We have also read:

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic....

https://community.intersystems.com/post/how-does-enslibftp-use-netftpses...

https://community.intersystems.com/post/ftp-file-download-all-files-no-f...

https://community.intersystems.com/post/using-and-debugging-netsshsessio...

https://community.intersystems.com/post/how-download-files-ftp-server-lo...

https://community.intersystems.com/post/how-uploaddownload-image-files-f...

https://community.intersystems.com/post/how-get-files-ftp-server

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

 

🎯 How would you accomplish this task, to be able to read a file from a FTP / SFTP server in HealthShare 2020?

 

Thanks for your time, and thank your for your replies.

🐱‍💻🐱‍💻🐱‍💻
 

Product version: IRIS 2020.1
Discussion (5)3
Log in or sign up to continue

..Adapter.Credentials.Username and ..Adapter.Credentials.Password

Credentials property of EnsLib.FTP.InboundAdapter is %String, so I expect an <INVALID OREF> error.

In general, I'd suggest to put your code inside a Try/Catch, something like:

	Set sc=$$$OK
	Try {
	    
	    ; your code here
	    
	} Catch CatchError {
		#dim CatchError as %Exception.SystemException
		Set sc=CatchError.AsStatus()
	}
	Quit sc

@Enrico Parisi's observation is the most likely reason for the failure. You can obtain the credentials (assuming you've set them up in Interoperability | Configure | Credentials) with
 

Set tCreds = ##class(Ens.Config.Credentials).%OpenId(..Adapter.Credentials,,.tSC)
Return:$$$ISERR(tSC) tSC

The tCreds.Username and tCreds.Password properties are available on success.

I'm puzzled by the fact that the two $$$LOGINFO() are present in the trace when an exception should have raised BEFORE the $$$LOGINFO().

The code posted is not the code that generated that trace. And this is very confusing.

Maybe the code was modified without restarting the Business Operation?