Você está na página 1de 4

System iNetwork Head Nav Subscribe Log In Contact Us Advertise User login Username: * Password: * Request new password

Search Primary links Forums Archives Code Blogs Podcasts Webcasts e-Learning Guides Newsletters About Us Contact Us About the Network Tech Editor Profiles Editorial Calendar Writers Kit Advertise Join Network Categories RPG Programming Other Languages Application Development Database/SQL Availability Security Systems Management Networking IT Mgmt/Careers Site Links Solutions Store Events UK Centre Jobs System iPortal Home Content FTP Send File Article ID: 57034Posted August 7th, 2008 in RPG Programming By:Bob Cozzi Making FTP Simple(r) with RPG IV There's little question that FTP is taking over the built-in ability for IBM "i" to send objects between systems. Using FTP gives us one interface to send files and other objects between different platforms (by "platforms" I mean operating systems) as well as between two System i boxes. With FTP, simply provide the rem ote IP address, the file you want to send, a few optional options and--bam!--it gets sent. The downside of FTP is that you have to know a few FTP commands, which it isn't difficult unless you haven't used FTP before. It is often something many RPG cod ers haven't learned until they get told to "FTP this file over to server XYZ.ABC .RST.WXY now." To make things easier for RPG coders who may be familiar with CL commands, I wan ted to create a simple FTP command that allows you to incorporate an FTP transfe r within your own CL applications or directly from the Command Entry Display. An

FTP expert might (and rightfully so) argue that it's easier to use straight FTP scripts rather than something else to send FTP files. Well, if that were always true, they wouldn't be using things like the ever-popular FileZilla to drag and drop files via FTP between virtually any operating systems. In fact, I even use FileZilla to upload and download savefiles and source files between Windows or Mac OS X and IBM "i". As an RPG coder, what I want is a command that allows me to say "Send this file using FTP. Here are the IP address, user ID, and password. Now, go do it." But n o such CL command existed at the time. So I wrote a simple command named FTP Sen d File (FTPSNDFILE) that allows you to do just that--send a file using FTP from Command Entry or within CL. This command was originally written in 2005, but I'v e since revised it and describe it along with its modifications below. Sending a File Using FTPSNDFILE The FTPSNDFILE command has a long list of parameters that have good defaults, an d it allows you to send any file directly through FTP without manually starting an interactive FTP session or writing an FTP script. The FTPSNDFILE command buil ds the FTP script on the fly and then runs that script by calling the FTP comman d. You can specify a remote system IP address or domain, the file and member you wa nt to send, and the target location. As is usually the case with CL commands tha t I write, I've selected a good set of default values for the parameters so that you only have to know the IP address, file name, user profile, and password. Th e rest of the parameters can be left to default. Here's a description of those p arameters. RMTSYS--Remote system. Specify the IP address or domain name of the system that will receive the file you are sending. FILE--Local file end using FTP. A , the FTPSNDFILE library name at name. Specify the qualified name of the file that you want to s value of *LIBL may be specified for the file's library. However command's processing program will convert *LIBL into the actual runtime.

MBR--Local member name. Specify the name of the member that you want to send. Th e default member name is *FIRST, but you may specify any member name you want or one of the special values, including: *FILE, *FIRST *LAST, or *ALL. In addition , you may specify a generic member name. TOFILE--Remote file name. Specify the name of the file on the remote system that will receive the data from the file you are sending. The file should already ex ist so that the external description is preserved. If the file does not exist, t he FTP server will create the file for you, but you won't like the results (a fl at file). If sending a *SAVF (Save File) make sure the save file exists on the r emote location or you'll need to copy the file to a save file once it has been F TP'd. *FROMFILE--Use this when the remote file name should be the same as the local fi le name as specified on the FILE parameter. TOMBR--Remote member name. Specify the name of the member into which the data is stored. You may specify either a member name or one of the following special va lues: *FROMMBR--Use this when the remote member name should be the same as the local m ember name as specified on the MBR parameter. This value must be specified when a generic local member name is specified or when *ALL is specified for the local member name (MBR) parameter. *TOFILE--The member name is the same as the remote file name specified on the TO

FILE parameter. REPLACE--Replace remote member's data. This parameter adds the "(Replace" parame ter to the FTP PUT command. Yes, FTP uses "(Replace" to indicate REPLACE(*YES). However, this parameter has no impact on the results when System i-to-System i t ransfers are being performed. On the System i, the target file/member's data is always replaced. RPG TnT: 101 Dynamic Tips n Techniques with RPG IV by Bob Cozzi The latest book from author Bob Cozzi contains 300 pages with 101 example RPG I V Tips and Techniques for everyday programming tasks, from date calculations, to regular express searches, to using APIs. Cozzi wrote down every cool technique he's found over the years, updated them, and consolidated them into this compact book that is a great desktop companion, and it includes full example source cod e. Order your copy today. USER--Remote FTP user profile. Specify the user profile of the user to sign on t o the remote system. PWD--Remote FTP user's password. Specify the password for the remote user. Note that this parameter's value is not recorded in the job log and must be entered e ach time you run FTPSNDFILE from Command Entry. From within a CL program, the pa ssword can be stored and passed to the FTPSNDFILE command within a CL variable. MODE--Transfer mode. Specify the kind of transfer to be performed. The valid cho ices are as follows: *BINARY--The transfer mode is IMAGE/BINARY. This is recommended for System i obj ects such as database files. *ASCII--The transfer mode is plain ASCII text. This transfer mode is valid for n on-database files, such as source file members. SRCFILE--The name of the source that will receive the generated FTP script. This source file should be as long as possible but at least 152 bytes in length (140 bytes for the source line and the usual 12 bytes for the source sequence and ch ange dates area). If this source file does not exist, it will be created with a record length of 1 52 bytes. The default source file name is as follows: Source file QFTPSRC, Libra ry QTEMP. SRCMBR--The FTP Script source member name. This is the name of the member into w hich the FTP script is generated. Specify any valid source member name, *FROMMBR , or *GEN. If the member exists, it is cleared; if it does not exist, it is adde d. The two special values for this parameter are as follows: *FROMMBR--The name specified on the MBR parameter is used as the member name for the FTP script. This member is added to the source file specified on the SRCFIL E parameter. *GEN--A member name using the following pattern is automatically generated: FSyy yymmdd, where FS is a constant, and YYYYMMDD is today's system name in YMD forma t. LOG--FTP message logging file. Specify the name of a source file that will recei ve the messages generated by the FTP command. Optionally, specify that the messa ges are to be delivered as they normally are, via the STDOUT (standard output) d evice. This parameter has the following special values: *STDOUT (or *STDIO)--Indicates that the FTP log is written to the standard outpu t device, which scrolls up the 5250 screen, similar to an old teletype interface . *NONE--The FTP log is not displayed. Unlike the SRCFILE parameter, the file specified on the LOG parameter must exist

because the FTPSNDFILE command will not create it. You may, however, use the sa me file name as the SRCFILE parameter, in which case the file is created due to its being specified on the SRCFILE parameter. LOGMBR--The member name where the FTP log is saved. The following special values may be specified instead of a specific member name. *FROMMBR--The name specified on the MBR parameter is used as the member name for the FTP script. This member is added to the source file specified on the SRCFIL E parameter. *SCRIPT--The Script source file member name is used as the LOG file's member nam e. The member from the SRCMBR parameter is used. *SRCMBR -- Same as *SCRIPT DSPLOG--Display the FTP log. If *YES is specified, the FTP log is displayed when the FTP transfer completes; if *NO, the FTP log is not displayed. -------------------------------------------------------------------------------Learn More Now The source code for the FTPSNDFILE command is featured in this week's second art icle. Click through to it and read about how the FTPSNDFILE command works, and h ow to use the cool helptext Panel Group that a user created for us.

Bob Cozzi is the host of RPG World Live, a live, weekly, 2-hour show on System i developments. It is aired on Fridays from 10:00 AM to Noon, Central time on ust ream.tv and on RPGWorld.com. Bob also produces RPG World, the most popular RPG I V developer conference of the year. Visit RPGWorld.com for details on the dates and the location of his 2009 RPG World Conference. Bookmark/Search this post with: Login to post comments Email this page Printer-friendly version Relate d Links Extend RPG with SQL Data Structures as Command Parameters Find Decimal Data Errors APIs by Example: Commands and Utilities--API Examples Revisited Qualified Object Names ProVIP Sponsors ProVIP Sponsors

Featured Links Sponsored Links Trevor Perry selects WebSmart PHP & Nexus Portal for KMR Systems - See Why! Barcode400 - Fully integrate & automate your labeling process. snap your back-end applications into any other application. FREE Paper: From WDSC to RDi - Making Software Change Easier with MKS. Footer Site Links Home Subscribe Now Advertise Contact Us Feedback Terms & Conditions Trademarks P rivacy Policy Copyright Penton Media