Skip to Content
avatar image
Former Member

Configuring FTP channel to pickup based on Filename

Hello Experts,

I have a requirment to pick up the file from NFS, only when the first 7 postions of the filename is Numerics and next two are alphabets .Else, Ignore.

Actual scenario :

-----------------------------

Pick up any files ( .pdf ) , and post them to an FTP ( Creating Dynamic directory ).

I have used File sender adapter to pickup the file and delete it when the file gets processed .

And, I have written Java mapping with the following condition to process only when the condition is satisfied  ( when first 7 postions of the filename are numerics and next two are alphabets ).

       String store = oldFileName.substring(0,7);

       String state = oldFileName.substring(7,9);

       Pattern p = Pattern.compile( "([0-9]*)" );

       Matcher str = p.matcher(store);

       Pattern p1 = Pattern.compile( "([A-Z]*)" );

       Matcher st = p1.matcher(state);

      

       if(str.matches())

           if(st.matches()){

       conf.put(KEY_FILEPATH, dir);

       conf.put(KEY_FILENAME, FileName);

Therefore, when filename condition doesn't matches the file from the source is note getting deleted. however, the file is getting copied into the Destination with wrong directory path.

To avoid this I would like to check if there is any condition in File Sender Adapter to check the filename conditions and then process the request .

Thanks for your valuable inputs 😊

Regards,

Ram

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 24, 2015 at 01:54 PM

    >>>Therefore, when filename condition doesn't matches the file from the source is note getting deleted. however, the file is getting copied into the Destination with wrong directory path.

    Destination folder is getting created as you are not throwing exception when the file name condition is not satisfied.

    If you want to throw exception and fail the message try using below method

    throw new StreamTransformationException


    How to create Java Mapping in SAP PI / PO

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 24, 2015 at 01:59 PM

    Hi Ram,

    I don't think file adapter supports regex in the filename patterns. It will support only placeholders * and ?.

    Defining Placeholders, File Name Masks, and Exclusion Masks - Advanced Adapter Engine - SAP Library

    Still if you want to handle this in the channel level itself, then you need to check for OS command possibility.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 24, 2015 at 02:13 PM

    Hi Rama,

    SFTP supports regex, but like Vishnu said  FTP adapter doesn't. The only ways, to develop a module bean or run OS are not the better ones either. If i was i will continue with the java mapping and if you have enough time i would try to do a module bean.

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 24, 2015 at 01:55 PM

    Try Run Operating System Command Before Message Processing option

    You can write Unix commands for checking file name and place files in respective directory if it matches your requirement.

    Add comment
    10|10000 characters needed characters exceeded