A frequent requirement in integration projects is the ability to send a file to an FTP server with a specific, often dynamic, name. Whether you need to preserve the name of the file you received or generate a new one based on business logic, here is how you achieve it in BizTalk Server.
📝 One-Minute Brief
By default, the BizTalk FTP adapter doesn’t always preserve the original filename. This post explains how to use the FTP.ReceivedFileName property and the %SourceFileName% macro to control output naming. It specifically highlights how to dynamically assign a filename within an Orchestration or by using a custom Pipeline Component to set the FILE.ReceivedFileName context property, which the FTP adapter then uses to name the outgoing file.
There are many approaches to this. I’ll give the simple (or basic) way to do. However, the BizTalk FTP adapter looks at the message context to decide what the remote file should be named. The most important property for this is: FILE.ReceivedFileName (within the http://schemas.microsoft.com/BizTalk/2003/file-properties namespace).
Set the FILE.ReceivedFileName and use the %SourceFileName% macro
In the orchestration Construct Message shape, add a Message Assignment shape, and then you can set the FILE.ReceivedFileName property for your flat file message as so:
This sets a context property that will then be used when you wire a static send port to your orchestration port. In your static send port, you specify the FTP adapter with a target file name like:
%SourceFileName%
And the FTP adapter then replaces the %SourceFileName% macro, giving you a filename like “20101125.txt”
So whether you use the file or FTP adapter it is always FILE.ReceivedFileName you need to use.
Controlling filenames in the FTP adapter is essential for maintaining traceability and meeting the requirements of external partners. By mastering context properties, you can ensure your files always land with the correct identity.
Author: Sandro Pereira
Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.
He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.
View all posts by Sandro Pereira
4 thoughts on “BizTalk FTP Adapter – How to send an FTP message with a specified filename”
Urgent Direct Client Requirement
Position : BizTalk Architect
Location: Baton Rouge, LA, USA
Contract Type : Permanent hire
Positions: 1
Required Skills :
Total IT exp of 10+years of exp
8+years of BizTalk experience in BizTalk 2004/2006/2006R2/2009
Excellent understanding and work experience on HIPAA and EDI
Either contract to Hire or permanent Hire
I have done this in the past without an orchestration. I was picking up the messages into a SQL receive adapter, so I included the filename I wanted in my source schema. Then I let the XML assembler in the pipeline promote the filename field into the File.ReceivedFileName context property.
This would not work for all scenarios, but it suited my needs.
Urgent Direct Client Requirement
Position : BizTalk Architect
Location: Baton Rouge, LA, USA
Contract Type : Permanent hire
Positions: 1
Required Skills :
Total IT exp of 10+years of exp
8+years of BizTalk experience in BizTalk 2004/2006/2006R2/2009
Excellent understanding and work experience on HIPAA and EDI
Either contract to Hire or permanent Hire
Please send the resume to : nraj@netvisionresources.com
Can you also display the file recordcount. What I mean is after the filename can you add the record count for the said filename?
I don’t know if I quite understand your question, but inside orchestration you can configure the sourcefilename as you want.
You can calculate the number of records by using an expression something like: rcount = xpath(message, “count(….)”);
And then set the property FILE.ReceivedFileName like:
OutputMsg(FILE.ReceivedFileName) = “Some name” + rcount + “.txt”
I have done this in the past without an orchestration. I was picking up the messages into a SQL receive adapter, so I included the filename I wanted in my source schema. Then I let the XML assembler in the pipeline promote the filename field into the File.ReceivedFileName context property.
This would not work for all scenarios, but it suited my needs.