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
.png)
.png)
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.cl…
https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic…
https://community.intersystems.com/post/how-does-enslibftp-use-netftpse…
https://community.intersystems.com/post/ftp-file-download-all-files-no-…
https://community.intersystems.com/post/using-and-debugging-netsshsessi…
https://community.intersystems.com/post/how-download-files-ftp-server-l…
https://community.intersystems.com/post/how-uploaddownload-image-files-…
https://community.intersystems.com/post/how-get-files-ftp-server
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
🎯 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.
🐱💻🐱💻🐱💻
Comments
..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=$$$OKTry {
; your code here
} Catch CatchError {
#dim CatchError as%Exception.SystemExceptionSet sc=CatchError.AsStatus()
}
Quit scThe Connect() method returns a %Boolean, not an %Status. You should check the ReturnCode and ReturnMessage properties to determine why it's failing.
@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) tSCThe 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?
Hi,
I believe your issues may be because you are using the EnsLib.FTP.InboundAdapter in your Business Operation, not the EnsLib.FTP.OutboundAdapter.
Please investigate the outbound adapter, which should also allow you to retrieve files.
- Steve