How to read nonXML file content over FTP

Hi,
I am submitting a file to the FTP port configured in the IS. I am able to read and process the content if my file is XML. My requirement is to post flat file (.txt) to the FTP port and i should be able to read the content of this file. I need the content for some processing.

How do I read the file content?

Thanks
Manoj

Hi Manoj,

After the FTP-Get , the output “content” is a byte object.

You can convert the same into Text by the service pub.string:bytesToString.

HTH
Bhavani Shankar

Your service should have the object “*ffdata” as the input. Once you have defined it, and send a *.txt file to this service via FTP, ‘*ffdata’ will be a inputstream object. You can convert to string or have it as bytes as required.

Let me know if you need more info.

Bahavani,

i am not using the client flow services. I mean i am not using the ftp:get. So i don’t get the content as byte object.

MAnohar,

I tried yiur solution. But did not work for me. Do i need to add any entry for the mime type? or do i need to make any other entries? I defined object “*ffdata” as input and converted it to string. As it is an object, i tried convetring directly( is that correct?). But did not get the content as output. Could you give me some more info please

Thanks
Manoj

Manoj,

IS launches various content handlers depending on the mime type of the object received. The mime type can also be determined by the file mime.types. All this is happening behind the scenes and it may be difficult to see what is called an when.

I suggest that at the beginning of your flow you do a savePipelineToFile and you look at the file to see if IS has created any variable like *ffdata with the content (you can also add a getFile and bytesToString [encoding UTF8] in the same flow to look at the content directly from the Developer)

bruno

Bruno,

I tried that. But could not find any variable like that. See the pipeline content below

<?xml>

<idataxmlcoder>
<record>
<value>c:\pipeline1.txt</value>
<record>
<value>ftp</value>
<record>
<value>OR.txt</value>
<value>text/plain</value>
</record>
</record>
</record>
</idataxmlcoder>

Thanks
Manoj

Manoj,

mmmh… Your pipeline looks funny to me. No name for the record?
Also what is the OR.txt file? Is it the file you are trying to FTP?
I see it is mapped to text/plain - I guess this is due to the .txt extension.

What version of IS are you running? If an “old” version you may have to create a specific content handler for text/plain. Let me know if you want details.

bruno

You can try the following
When you FTP the file to the service, specify the content-type as "application/x-wmflatfile ". This should definitely bring in the *ffdata stream object inside your service.

Or if you know the extension of your file (like *.txt, *.dat) is fixed, you can add it to the file \IntegrationServer\lib\mime.types.

Btw, please make sure your WmFlatFile package is loaded as a startup service initialises the content handler for "application/x-wmflatfile ".

p.s. The pipeline will be empty until you specify the right parameters for the content handler to provide the correct stream object. So it doesnt help to try debugging with savePipeline service.

Good luck

Manoj

Create input feild called node and of type OBJECT. When you FTP .txt file then *node will automatically take stream input from the file.
You have to FTP the file into directory : ns/folder/service
Then you can do streamToBytes or streamToString etc.
I just did this couple of days ago and it worked for me.

Good luck.

Sai

Hi Bruno, Manohar

I am yet to try your suggestions as i am held up with something else @ work. I shall revert after trying that out. Meanwhile one doubt, do i need WmFlatFile package for having this worked? I don’t have that loaded. Do i have to install it separately? i am running IS 4.6.

Sai, I did try this first time. but could succeed only for XML, but not for .txt file. For XML, i used documentToRecord to convert from node to record and it was fine.

Thanks
Manoj

Sai, one quick question. Which version on IS are you using? Mine is 4.6 and I tried the same but could not get the content out.

Manohar, what about your version. You are talking abount a package WmFlatFile. I could not find it in 4.6

Thanks
Manoj

WmFlatfile is only in 6.0. I guess because it provides the content handler in the package, the stream object appears as *ffdata.

Did you try as Sai has suggested in his post. If it still does not work, then you can create your own content handler. It is in the webMethods documentation. There has also been a posting for creating a generic content handler.

Manoj,

I’m using 6.0.1. I dont see the reason why it is not working. Yesterday i again tried that service by FTPing .txt file. It worked fine. I’m emailing the output to mail box. I’m getting the complete file contents.

Sai

  1. I defined *node in my input field.
  2. Invoked streamToBytes
  3. Invoked bytesToString
  4. smtp to my mail box with the string output of bytesToString.

Testing:
From my DOS prompt:
Ftp login to wmhost 8021
change dir to ns/saifolder/testService
put text.txt

I’m getting the email with the file content.

Good Luck

Sai

Sai,

Looks like this issue is bcoz i am using 4.6. The documentation of 4.6 explains submitting a XML through FTP and processing it. I trid that and it worked fine. Problem is only when the file is not XML. Flat file is supported in 6.0 and that may be the reason you could do it cooly.

As Manohar suggested, i may have to write a content handler to handle flat files over FTP in 4.6. I will try that.

Thanks
Manoj

Sai,

If you have the WmFlatFile package installed then you can try the following :

put file.txt file.txt:application/x-wmflatfile

This will initiate the content handler for the flat files.

The other option is not specify the content type and just use

put file.txt

If you do that, you should have a pipeline variable called contentStream. It is an object that extends java.io.InputStream. So you can easily write a java service to read from it.

I’d like to comment my case, i’m using wm 4.6 and i created a content handler for receive the flat files and taking each line as an order line from a partner, i created a java service that makes this process, just send the flat file to the service and automatially the content handler recongnize the type (mime type text/csv) and is converted to a string list.

All that i have then is to loop over this string list.

I hope it can help you.

Manoj

define edidata input field as string or inputstream.

If you define as string you should directly read your data in the string.

I tested this in version 4.6

disregard it if you have already done this.

Sai