locked
FTP Adapter - check for file exists before uploading RRS feed

  • Question

  • I'm using the FTP Adapter that comes with BizTalk 2013. I'd like to add logic that says - if file exists, do not upload file (from disc). Instead, move the file (from disc) to an "duplicates" directory and then send out an email notifying that there was a duplicate file.

    How would I do this?

    1) Someone posted a similar question a while back and said you'd basically have to write your own adapter? If this is the case, can someone point me to how to get started? I have no issue writing the FTP Library code (I already have something similar), so I'm just looking for pointers on how to create my adapter. BTW, I'm fairly new to BizTalk.

    http://social.technet.microsoft.com/Forums/lync/en-US/89521f6d-1db3-4551-93b1-5d15940ec97e/ftp-adapter-to-check-duplicate-files?forum=biztalkgeneral

    2) Alternatively, would it be simpler if we could in fact use a custom pipeline component? Something that intercepts the FTP Adapter before it does the actual FTP'ing? e.g. I can use my FTP library to perform a directory listing to search for the file on the target server and add all my archive/disc and email logic. I roughly know how to create custom pipeline components, though I'm not entirely sure how I would get my input variables (i.e. file name, and settings from the FTP Adapter).

    Feed back would be greatly aprpeciated!


    Thanks.

    Thursday, February 6, 2014 9:43 PM

Answers

  • The FTP Adapter has a "Before Put" property you can use to specify commands to send before the PUT operation.

    You should be able to use that to solve the 'move to duplicates folder' requirement.

    As for detecting this and sending a notification, you could have another FTP Receive Location that then Retrieves the 'duplicate' files and sends a notification or whatever. The problem here is it would retrieve the file.

    To answer you specific questions:

    1. Start with the File Adapter sample in the SDK folder.  After renaming everything, you'd mostly just have to change the send code from a File operation to FTP.  Then add the logic to detect the duplicate on the server.

    2. A pipeline component would be fairly easy to write, but the tricky issue is getting the notification back to BizTalk. You could just send an e-mail directly from the component.  Adapter properties are not easily accessible in the Pipeline runtime context but you can just as easily set matching properties in the Pipeline Component.

    • Marked as answer by Angie Xu Thursday, February 13, 2014 1:11 AM
    Friday, February 7, 2014 2:27 PM
    Moderator

All replies

  • As you suggested, you can write a custom adapter where you can do duplicate check, file move to duplicate directory and email notification.  But this is trying to cover many business processes under adapter functionality whose intend purpose is just to work with a transport, speak the transmission protocol and transfer the file.

    Custom adapter: But still you can do these functionalities in custom adapter.

    For article, white papers and webcast for developing custom adapter refer this MSDN page:

    Developing Adapters using the BizTalk Adapter Framework

    You can still use BizTalk adapter wizard which gives you the template files including registry key required for registering the custom adapter. This may need Visual Studio 2005 to get the template project created. The export Visual Studio 2005 to your latest version to get the template for your latest version. And write your FTP library code in the placeholders.

    Or refer the SDK for sample custom adapter and replace those custom functionalities to yours to make and update SDK samples work for you.

    http://biztalkadapterwizard.codeplex.com/releases/view/3892

    No to custom pipeline:  Your functionalities are not meant for custom pipeline processing. Pipelines are meant for preparing the received message for further processing or preparing the message/file to be sent out. Custom pipeline is not the correct place to write your functionalities.

    Try to isolate the functionalities and handle it different modules and don’t pack everything in custom adapter. For example, you can just use custom adapter to FTP the file, if it’s a duplicate file transfer the file to different folder location. You can (or ask the team who own the FTP server) to send an email if the duplicate folder receives a file. This would improve the performance of the adapter.


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    Thursday, February 6, 2014 11:00 PM
  • The FTP Adapter has a "Before Put" property you can use to specify commands to send before the PUT operation.

    You should be able to use that to solve the 'move to duplicates folder' requirement.

    As for detecting this and sending a notification, you could have another FTP Receive Location that then Retrieves the 'duplicate' files and sends a notification or whatever. The problem here is it would retrieve the file.

    To answer you specific questions:

    1. Start with the File Adapter sample in the SDK folder.  After renaming everything, you'd mostly just have to change the send code from a File operation to FTP.  Then add the logic to detect the duplicate on the server.

    2. A pipeline component would be fairly easy to write, but the tricky issue is getting the notification back to BizTalk. You could just send an e-mail directly from the component.  Adapter properties are not easily accessible in the Pipeline runtime context but you can just as easily set matching properties in the Pipeline Component.

    • Marked as answer by Angie Xu Thursday, February 13, 2014 1:11 AM
    Friday, February 7, 2014 2:27 PM
    Moderator