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;
| Title | Under | Posted on |
|---|---|---|
| MD5 - SHA checksum of a file. | PeopleSoft Technical | 02/07/2012 - 5:29am |
| nVision Tabular Report through PIA with prompts | PeopleSoft Technical | 02/02/2012 - 10:07pm |
| Can we create an AE to mass update Position - Jobcode data? | PeopleSoft Technical | 01/18/2012 - 3:11am |
| Pay Components on job data can be defaulted and setup based on the rules? | PeopleSoft Functional | 01/05/2012 - 4:58am |
Comments
Can i also use this for sftp or ftps ?
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
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.
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..
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.
Other way around is write a shell script .. and call that script in people code using exec function..
Find the heading "FTP using PeopleCode PutAttachment() inside App Engine"
http://bipinps.blogspot.com/2009/09/peoplesoft-peoplecode-xmldoc.html
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!
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
Post new comment