Click here to read this Tutorial from beginning
Member Type Text
FTP_IN TXT FTP Input file
FTP_OUT TXT FTP Output file
Now we need to override these files either in a CL or RPGLE program before using them in FTP.
OVRDBF FILE(INPUT) TOFILE(*LIBL/SRC) MBR(FTP_IN)
OVRDBF FILE(OUTPUT) TOFILE(*LIBL/SRC) MBR(FTP_OUT)
Now your sample code for the RPGLE program doing the FTP
finput uf a e disk rename(src:i_rec)
f usropn
foutput if a e disk rename(src:o_rec)
f usropn
*Date/Time Stamps
d ds
d @DateTime z
d @DteStmp d overlay(@DateTime : 1)
d @TimStmp t overlay(@DateTime : 12)
* Execute A Command
d ExcCmd PR ExtPgm('QCMDEXC')
d Cmd_Str 512a Options(*VARSIZE)
d Const
d Cmd_Len 15p 5 Const
d $date s 10a
d $time s 10a
d @CmdStr s 512a inz
d @Apostr s 1a inz(X'7D')
//Open the input file
c open input
//Delete any data that may be there from previous run
c dou %eof(input)
c read input
c if %eof(input)
c leave
c endif
c delete i_rec
c enddo
//First we write the Userid and Password
c eval srcdta = %trim($userid) + ' ' +
c %trim($password)
c write i_rec
//In case we need to set the NAMEFMT
c eval srcdta = 'namefmt 1'
c write i_rec
//Set remote directory
c eval srcdta = 'cd ' + %trim($remote_dir_path)
c write i_rec
//Set local directory
c eval srcdta = 'lcd ' + %trim($local_dir_path)
c write i_rec
//Put the file
c eval srcdta = 'put ' + %trim($file_name)
c write i_rec
//Put the file in a different name
c eval srcdta = 'put ' + %trim($from_file_name) + ' ' +
c %trim($to_file_name)
c write i_rec
//Get the file
c eval srcdta = 'get ' + %trim($file_name)
c write i_rec
//Get the file in a different name
c eval srcdta = 'get' + %trim($from_file_name) + ' ' +
c %trim($to_file_name)
c write i_rec
//Get the file in a different name but it already exists
c eval srcdta = 'put ' + %trim($from_file_name) + ' ' +
c %trim($to_file_name) + ' (replace'
c write i_rec
//Delete a file on the remote system
c eval srcdta = 'delete ' + $file_name
c write i_rec
//Quit ftp
c eval srcdta = 'quit'
c write i_rec
//Close the input file
c close input
//Tag your file in the FTP response or outfile file for easy lookup – not necessary
//Get time stamp
c time @datetime
c move @DteStmp $date
c move @TimStmp $time
// Open Output file
c open output
//Write file name with date and time
c eval srcdta = '--->'
c write o_rec
c eval srcdta = 'FTP for file ' + %trim($file_name)+
c ' starting at ' + $date + $time
c write o_rec
//Close the output file
c close output
//FTP to remote system
c eval @CmdStr = 'FTP RMTSYS(' + @Apostr +
c %Trim($hostname or IP address) + @Apostr + ')'
c callp ExcCmd(%Trim(@CmdStr) :
c %Len(%Trim(@CmdStr)))
//All done
No comments:
Post a Comment
NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.