且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

BizTalk 2010动态FTP发送端口输出目录和文件名称问题

更新时间:2022-10-15 11:55:00

文件命名是在您提供FTP URL的地址属性中完成的。事实上,你甚至可以在那里使用宏。试试看:

  FTPSendPort1(Microsoft.XLANGs.BaseTypes.Address)=ftp:// sample-servername-stage:721 /SomeFolder/SomeFileName_%datetime%.xml

另一个检查文件夹是否存在的问题FTP和创建它们,我认为你必须编写一个自定义管道组件。


I have a rather complex requirement - that I have to drop a very specifically named file in an FTP location, and the trick here is that I would often have to drop it into a new location and with a new file name each time (both directory name and file name depending on the year, month, date and time). Obviously, for this purpose I chose to use a Dynamic Send Port, which I have configured using a MessageAssignment Shape.

A file will be generated each day. I need to drop it in a remote location in this form: sample-servername-stage/default/file/ftp/PaymentReports/YYYY/MM_[MonthName]/PaymentReportYYYYMMDD_HHMISS

For example, for a file posted on March, 2 2016 at 6:45pm, we would have:

sample-servername-stage/default/file/ftp/PaymentReports/2016/03_March/PaymentReport20160302_184500

Here's the code I have in the MessageAssignment Shape:

FTPSendPort1(Microsoft.XLANGs.BaseTypes.Address) = "ftp://sample-servername-stage:721";
FTPSendPort1(Microsoft.XLANGs.BaseTypes.TransportType) = "FTP";

Output(FTP.CommandLogFileName) =  "D:\\BiztalkLogs\\FTPLog\\DynamicFTPLog.txt";
Output(FTP.UserName) =  "sampleUsername";
Output(FTP.Password) =  "samplePassword";
Output(FTP.BeforePut) = "MKD " + Variable_1 + ";CWD " + Variable_1;

FTPSendport1 - name of the Dynamic Send Port.

Output - name of the Output message.

Variable_1 - variable where I will store the directory name to be created.

Here are the biggest issues:

  1. I need to check if a directory already exists - the year, then navigate in and check if the month already exists. If they exist I simply go in there and drop the file. If not, I create it and drop the file in there.

  2. I need to name the file with the date time specifics in the format shown above. In addition to the code shown above, I have tried a number of things including setting FILE.ReceivedFileName, FTP.ReceivedFileName properties etc. Nothing seems to work. This may be because I cannot use the macro %SourceFileName% anywhere. Because of this it keeps dropping the file into the location with a GUID name instead of the one I set. It behaves as though it completely skips/overlooks the command where I set the file name.

I'm thoroughly confused at this point. I'm not sure of how I can mix checking conditions (if the folders already exist etc.) with FTP commands, and especially not sure of how to do this within an orchestration.

The file naming is done in the address property where you provide the FTP URL. In fact you can even use macros in there. Try that:

FTPSendPort1(Microsoft.XLANGs.BaseTypes.Address) = "ftp://sample-servername-stage:721/SomeFolder/SomeFileName_%datetime%.xml"

For you other problem of checking if folders exists on the FTP and creating them, I think you'll have to write a custom pipeline component.