FTP a File Using PeopleCode

Your rating: None Average: 4.3 (18 votes)

Here is a function to FTP a file on a server using PeopleCode.
Local string &FtpUserID;
Local string &FtpPassword;
Local string &FtpURL;
Function ftp_file;
&FtpUserID = “user_id”;
&FtpPassword = “password”;
&FtpURL = “directory_name/subdirectory_name”;
&targetFile = “File_Name”;
/* Set ftp string */
&Ftp_my_file = “ftp://” | &FtpUserID | “:” | &FtpPassword | “@” | &FtpURL;
/*** It is always a good practice to check to see if local file exists before trying to transfer it ***/
If FileExists(&FILEPATHNAME, %FilePath_Absolute) Then
/*** Sending file… FILEFATHNAME is the path and the name of the file, while targetFile can be used to change the name of the file if need be ***/
&RetCode = PutAttachment(&Ftp_my_file, &targetFile, &FILEPATHNAME);
/* make sure to check the retcode by the built-in PeopleCode function PutAttachment to get the result of your ftp attempt */
Evaluate &RetCode
When %Attachment_Success
MessageBox(0, “File Attachment Status”, 0, 0, “File transfer succeeded”);
Break;
When %Attachment_Failed
MessageBox(0, “File Attachment Status”, 0, 0, “File transfer failed”);
Break;
When-Other
MessageBox(0, “File Attachment Status”, 0, 0, “File transfer failed, Return Code is ” | &RetCode | “. Please refer to PeopleCode Reference for Return Code description. Search for AddAttachment function.”);
End-Evaluate;
Else
MessageBox(0, “File Status”, 0, 0, “File ” | &FILEPATHNAME | ” doesn’t exist. FTP transfer Failed.”);
End-If;
End-Function;

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
Guest's picture
Guest (not verified)
Re: FTP a File Using PeopleCode

Can i also use this for sftp or ftps ?

Lepa's picture
User offline. Last seen 43 weeks 6 days ago. Offline
Joined: 06/23/2008
Posts: 591
Re: FTP a File Using PeopleCode

Sorry but the PutAttachment delivered PeopleSoft function doesn't support SFTP. You will have to develop custom scripts to do that for you.

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

PS_LoneRanger's picture
PS_LoneRanger (not verified)
FTP using peoplecode

oh man, you're the man

I had this java based solution, that caused memory management problems, your solution allows me to screw that out.

Thanks a lot.

Ven's picture
Ven (not verified)
Re: FTP a File Using PeopleCode

Hello,

Thanks for your PeopleCode. I used your code and got this error "File transfer failed, Return Code is 8."

Could you respond asap and please respond what went wrong.

Thanks, Ven..

Carl's picture
Carl (not verified)
Re: FTP a File Using PeopleCode

I was receiving error code 8 as well. I found that it had to do with special characters in the username or password. In my cases, 8 meant that I was able to connect to the server, but couldn't authenticate.

The username I was able to resolve by escaping the backslash in "domain\user" by using "domain\\user".

However, if the password contained a special character like $ or !, I wasn't able to escape those, so I changed the password to alpha numeric only.

rahulkhandelw's picture
User offline. Last seen 8 years 14 weeks ago. Offline
Joined: 10/16/2009
Posts: 34
Re: FTP a File Using PeopleCode

Other way around is write a shell script .. and call that script in people code using exec function..

bipin.jethwani@gmail.com's picture
Joined: 12/01/2009
Posts: 1
Re: FTP a File Using PeopleCode

Find the heading "FTP using PeopleCode PutAttachment() inside App Engine"
http://bipinps.blogspot.com/2009/09/peoplesoft-peoplecode-xmldoc.html

Guest's picture
Guest (not verified)
Re: FTP a File Using PeopleCode

Hello everybody,
How can I use putattachment function to upload a huge pdf file to database? Any sample code is appreciated.
Do I need to use CREATE RECORD function to create the FILE_ATTDET_SBR and FILE_ATTACH_SBR records and then make separate entries into these records? I am at a loss.

Please advice.

Thanks!

Rocky's picture
Rocky (not verified)
Re: FTP a File Using PeopleCode

Hi,
Thanks a lot for posting this code snippet. I have few questions though:
Will this code work for both NT as well as unix process scheduler servers?
I am planning to pass the fields source file path, source file name, target file name all from the run control page. Do we have to use any particular format in specifying these in case of NT and Unix servers.

Thanks,
Rocky

Ankit's picture
Ankit (not verified)
Re: FTP a File Using PeopleCode

Hi

I want to transfer multiple files from one folder, can i do a full folder transfer otherwise
how do i keep giving the different "&targetFile" name for each file (although i do not need to change the name of files i am transferring).

Any help is appreciated.

Thanks
Ankit

Guest's picture
Guest
Re: FTP a File Using PeopleCode

Hi All,

i want to attach a file resides in a FTP to be send as attachement in sendmail. Please let me know if any1 have don this.

Thanks in advance

Guest's picture
Guest
Re: FTP a File Using PeopleCode

&nReturnCode = PutAttachment(URL.ZZ_CATS_FILE_EXPORT, "inbound/locations/" | &File_Name, &File_Name, "PS_FILEDIR");