Tuesday, September 29, 2009

Transferring files from ftp path to any folder

Recently got a small enhancement requirement for attaching a word file into a mail send to the recruiter, which is stored in a FTP path. First I tired the ViewAttachment() function to access the file.

Tried to catch the file URL which got generated to send in the mail. As the URL generated was dynamic, it was not possible.

The second try was to take the file from the ftp path and put it into a folder in the appserver and attaching to the mail send to the recruiter. And the idea worked fine.

  • How to get the file from ftp and transfer it to the desired folder?

This can be accomplished using the GetAttachment() function, which will take the file from the FTP path specified and will transfer to the folder specified.


Below is the sample code for the functionality.

/*********To transfer the file, File_invitaton.doc, from ftp://anonymous:passowrd@ to \\\TF9DEV_temp\ File_invitaton.doc which is an appserver path******/

&nbr_RetCode = GetAttachment("ftp://anonymous:passowrd@", "File_invitaton.doc", "\\\TF9DEV_temp\ File_invitaton.doc ");


Local number &MAIL_FLAGS;


&MAIL_TO = "ps@ps.com";

&MAIL_CC = "";

&MAIL_BCC = "";

&MAIL_SUBJECT = "ps@gmail.com";

&MAIL_TEXT = "Sending an email from PeopleCode.";

/*********for attaching the file in the mail***************************/

&MAIL_FILES = "\\\TF9DEV_temp\ File_invitaton.doc ";

&MAIL_TITLES = "Requested File";

&MAIL_FROM = "test@test.com";

&MAIL_SEP = ";";


&REPLYTO = "";

&SENDER = "";


/*********Successfully Sent the mail J***************************/

/*********We can do the reverse functionality using the PutAttachment() function***************************/

/*********Make sure that you have the right to access the FTP path and the file exists J***********************/


No comments:

Post a Comment