JointLantic

FTP a File Using PeopleCode

FTP a File Using PeopleCode

There 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;

 

credit : (borrowed from Lepa @ CompShack).

Exit mobile version