Search This Blog

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@222.12.13.52/docfolder to \\222.12.13.54\TF9DEV_temp\ File_invitaton.doc which is an appserver path******/

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

Local string &MAIL_CC, &MAIL_TO, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TITLES, &MAIL_TEXT, &MAIL_FILES, &MAIL_FROM, &REPLYTO, &SENDER;

Local number &MAIL_FLAGS;

&MAIL_FLAGS = 0;

&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 = "\\222.12.13.54\TF9DEV_temp\ File_invitaton.doc ";

&MAIL_TITLES = "Requested File";

&MAIL_FROM = "test@test.com";

&MAIL_SEP = ";";

&CONTTYPE = "";

&REPLYTO = "";

&SENDER = "";

&RET = SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT, &MAIL_FILES, &MAIL_TITLES, &MAIL_FROM, &MAIL_SEP, &CONTTYPE, &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