Home > AS/400 Tips > iSeries administrator tips > Automatically save, FTP and restore objects to a remote system from a single command
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES ADMINISTRATOR TIPS

Automatically save, FTP and restore objects to a remote system from a single command


Andy Norton
07.19.2004
Rating: -4.60- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This tool allows you save, FTP and restore up to 10 objects at a time to a remote system using a single command. The command prompts you for the object names, the library name, the object type, the remote system name (or IP address) and your password on the remote system. The additional parameters that appear after pressing F10 allow you to change the name of the library that the objects are restored to, or alter the user name, the FTP logs in as on the remote system. (The default is the same user ID you are using on the sending system.) The program works by saving the objects to a save file in QTEMP, building an FTP script, sending the save file via FTP to the remote system and issuing the restore command in the same FTP script. Nothing needs to be loaded on the remote system. (The FTP server must be started though.) The program will work as long as you have a user ID with sufficient authority and the remote operating system on the target system is the same level or higher than the sending system -- although the program could easily be modified to save at a previous release.

Debugging FTP failures
The program will create a file called FTP in QTEMP which has two members (FTPIN and FTPOUT). You can look at these members to examine the FTP script that was run on the remote system (FTPIN) and look at the response received (FTPOUT)

I'm currently working on a similar tool to provide the same functionality for IFS objects.

Installation

Firstly, you will need to create a simple DDS source member called FTP in QGPL/QDDSSRC. This defines the FTP script file and log file.



Code

 
********************** Beginning of data  *****************************
0001.00      A          R FTPF
0002.00      A            FTPR         300   B
****************** End of data ****************************************

This is the command source to create the command (I've called it
OBJTOSYS)
0001.00              CMD        PROMPT('Copy Object To Remote System')          
0002.00              PARM       KWD(OBJNAME) TYPE(*CHAR) LEN(10) MIN(1) +       
0003.00                           MAX(10) PROMPT('Object Name')                 
0003.01              PARM       KWD(LIBRARY) TYPE(*CHAR) LEN(10) MIN(1) +       
0003.02                           PROMPT('Library Name')                        
0003.03              PARM       KWD(OBJTYPE) TYPE(*CHAR) LEN(7) DFT(*ALL) +     
0003.04                           MIN(0) PROMPT('Object Type')                  
0003.05              PARM       KWD(REMOTESYS) TYPE(*CHAR) LEN(15) MIN(1) +     
0003.06                           PROMPT('Remote System')                       
0003.08              PARM       KWD(PASSWORD) TYPE(*CHAR) LEN(10) MIN(1) +      
0003.09                           DSPINPUT(*NO) PROMPT('Password of Remote +    
0003.10                           System')                                      
0004.00                                                                         
0005.00            PARM       KWD(REMOTELIB) TYPE(*CHAR) LEN(10) DFT(*LIB) +  
0006.00                           MIN(0) PMTCTL(*PMTRQS) PROMPT('Remote +       
0007.00                           Library Name')                                
0008.00            PARM       KWD(RMTUSER) TYPE(*CHAR) LEN(10) DFT(*SAME)+
0009.00                           MIN(0) PMTCTL(*PMTRQS) PROMPT('Remote +    
0010.00                           User Name')      
 
         

The main CL source (OBJTOSYS)             

        *************** Beginning of data ************************************* 
0001.00              PGM        PARM(&OBJECTNAME &LIBRARY &OBJTYPE +            
0002.00                        &REMOTESYS &PASSWORD &REMOTELIB &RMTUSER)     
0003.00              DCL        VAR(&OBJECTNAME) TYPE(*CHAR) LEN(102)           
0003.01              DCL        VAR(&OBJECTS) TYPE(*CHAR) LEN(109)              
0003.02              DCL        VAR(&OBJECT) TYPE(*CHAR) LEN(10)                
0004.00              DCL        VAR(&LIBRARY) TYPE(*CHAR) LEN(10)               
0005.00              DCL        VAR(&REMOTESYS) TYPE(*CHAR) LEN(15)             
0006.00              DCL        VAR(&PASSWORD) TYPE(*CHAR) LEN(10)              
0008.00              DCL        VAR(&REMOTELIB) TYPE(*CHAR) LEN(10)             
0008.01              DCL        VAR(&USER) TYPE(*CHAR) LEN(10)                  
0008.02              DCL        VAR(&SCRIPTLINE) TYPE(*CHAR) LEN(300)           
0008.03              DCL        VAR(&OBJTYPE) TYPE(*CHAR) LEN(7)                
0008.04              DCL        VAR(&RMTUSER) TYPE(*CHAR) LEN(10)               
0008.05              DCL        VAR(&NBRELEM) TYPE(*DEC) LEN(5 0)               
0008.06              DCL        VAR(&COUNTER) TYPE(*DEC) LEN(5 0)               
0008.07              DCL        VAR(&POSITION) TYPE(*DEC) LEN(5 0)              
0008.08              DCL        VAR(&SAVOBJCMD) TYPE(*CHAR) LEN(300)          
0008.09                                                                       
0008.10 /*CHECK NUMBER OF OBJECTS PASSED BY CMD BUILD OBJ VAR */
0008.11          CHGVAR     VAR(&NBRELEM) VALUE(%BIN(&OBJECTNAME 1 2))    
0008.12  LOOP:       CHGVAR     VAR(&POSITION) VALUE(&COUNTER * 10 + 3)       
0008.13              CHGVAR     VAR(&OBJECT) VALUE(%SST(&OBJECTNAME +         
0008.14                           &POSITION 10))                              
0008.15          CHGVAR     VAR(&OBJECTS) VALUE(&OBJECTS *TCAT ' ' *CAT + 
0008.16                           &OBJECT)                                    
0008.17              CHGVAR     VAR(&COUNTER) VALUE(&COUNTER + 1)            
0008.18              IF         COND(&COUNTER *LT &NBRELEM) THEN(GOTO +      
0008.19                           CMDLBL(LOOP))                              
0008.21              CHGVAR     VAR(&OBJECTS) VALUE(%SST(&OBJECTS 2 108))    
0008.22                                                                      
0008.23              IF         COND(&REMOTELIB = '*LIB      ') THEN(CHGVAR +
0008.24                           VAR(&REMOTELIB) VALUE('*SAVLIB'))          
0008.25              RTVJOBA    USER(&USER)                                  
0008.26              IF         COND(&RMTUSER *NE '*SAME     ') THEN(CHGVAR +
0008.27                           VAR(&USER) VALUE(&RMTUSER))                 
0009.00                                                                       
0009.01 /* CHECK FTP SCRIPT FILE  EXISTS - IF SO SKIP FILE CREATE */
0009.02              CHKOBJ     OBJ(QTEMP/FTP) OBJTYPE(*FILE)                 
0009.03              MONMSG     MSGID(CPF9801 CPF3142) EXEC(DO)               
0009.04                                                                       
0009.05 /* CREATE FTP SCRIPT FILE AND ADD MEMBER FOR FTP LOG    */            
0009.06              CRTPF      FILE(QTEMP/FTP) SRCFILE(QGPL/QDDSSRC) +       
0009.07                           SRCMBR(FTP) MBR(FTPIN) MAXMBRS(2)           
0009.08              ADDPFM     FILE(QTEMP/FTP) MBR(FTPOUT)                 
0009.09              GOTO       CMDLBL(CRTSAVF)                             
0009.10              ENDDO                                                  
0009.11                                                                     
0009.12 /* CLEAR FTP FILES IF THEY ALREADY EXIST  */                        
0009.13              CLRPFM     FILE(QTEMP/FTP) MBR(FTPIN)                  
0009.14              CLRPFM     FILE(QTEMP/FTP) MBR(FTPOUT)                 
0009.15                                                                     
0009.16 /* CHECK IF SAVF IN QTEMP EXISTS - IF SO SKIP FILE CREATE */
0009.17  CRTSAVF:    CHKOBJ     OBJ(QTEMP/SAVFXXXXXX) OBJTYPE(*FILE)          
0009.18              MONMSG     MSGID(CPF9801 CPF3142) EXEC(DO)               
0010.00              CRTSAVF    FILE(QTEMP/SAVFXXXXXX) TEXT('Save File to +   
0011.00                           transfer objects to remote system')         
0011.01              GOTO       CMDLBL(SAVOBJ)                                
0011.02              ENDDO                                                    
0011.03                                                                       
0011.04 /* CLEAR SAVE FILE IF IT ALREADY EXISTS               */              
0011.05              CLRSAVF    FILE(QTEMP/SAVFXXXXXX)                        
0011.06                                                                      
0011.07 /* BUILD SAVOBJ COMMAND AND SAVE OBJECTS  */                         
0011.08  SAVOBJ:  CHGVAR     VAR(&SAVOBJCMD) VALUE('SAVOBJ OBJ(' *CAT +   
0011.09                           &OBJECTS *CAT ') LIB(' *CAT &LIBRARY *CAT +
0011.10                           ') DEV(*SAVF) OBJTYPE(' *CAT &OBJTYPE +    
0011.11                           *CAT ') SAVF(QTEMP/SAVFXXXXXX)')           
0011.12              CALL       PGM(QCMDEXC) PARM(&SAVOBJCMD 300)            
0013.01                                                                      
0013.02 /* BEGIN BUILD OF FTP SCRIPT */                                      
0013.03           CHGVAR     VAR(&SCRIPTLINE) VALUE(&USER *TCAT ' ' *CAT +  
0013.04                           &PASSWORD)                                   
0013.05              CALL       PGM(FTPSCRBLD) PARM(&SCRIPTLINE)               
0013.06              CHGVAR     VAR(&SCRIPTLINE) VALUE('namefmt 1')            
0013.07              CALL       PGM(FTPSCRBLD) PARM(&SCRIPTLINE)               
0013.08              CHGVAR     VAR(&SCRIPTLINE) VALUE('bin')                  
0013.09              CALL       PGM(FTPSCRBLD) PARM(&SCRIPTLINE)               
0013.10              CHGVAR     VAR(&SCRIPTLINE) VALUE('put +                  
0013.11                           /qsys.lib/qtemp.lib/savfxxxxxx.savf +        
0013.12                           /qsys.lib/qtemp.lib/savfxxxxxx.savf')       
0013.13              CALL       PGM(FTPSCRBLD) PARM(&SCRIPTLINE)              
0013.14              CHGVAR     VAR(&SCRIPTLINE) VALUE('quote rcmd RSTOBJ +   
0013.15                           OBJ(' *CAT &OBJECTS *CAT ') SAVLIB(' +      
0013.16                           *CAT &LIBRARY *CAT ') DEV(*SAVF) +          
0013.17                           SAVF(QTEMP/SAVFXXXXXX) ALWOBJDIF(*ALL) +    
0013.18                        MBROPT(*ALL) RSTLIB(' *CAT &REMOTELIB *CAT ')')
0013.19              CALL       PGM(FTPSCRBLD) PARM(&SCRIPTLINE)              
0013.20                                                                       
0013.21 /* RUN FTP SCRIPT */                                                   
0013.22              OVRDBF     FILE(OUTPUT) TOFILE(QTEMP/FTP) MBR(FTPOUT)     
0013.23              OVRDBF     FILE(INPUT) TOFILE(QTEMP/FTP) MBR(FTPIN)       
0014.00              FTP        RMTSYS(&REMOTESYS)                             
0015.00              ENDPGM                                                    
        ****************** End of data ****************************************    
 

Simple RPG program to build the FTP script (FTPSCRBLD)

*********************** Beginning of data ***************************** 
0009.00      FFTP     O   E
DISK                             0010.00      C           *ENTRY
PLIST                                        0011.00      C
PARM           FTPR                          0012.00      C*
0015.00      C                     WRITEFTPF
0016.00      C*
0017.00      C                     SETON                     LR
****************** End of data ****************************************

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries administrator tips
Translating Linux for IBM i admins: Using GUI to make it easy
Translating Linux for IBM i admins: Working with jobs and networking
OpenOffice: What to know before making the transition from Microsoft Office
OpenOffice: An enterprise open source solution
Database performance comparisons on IBM i
Translating Linux for IBM i admins: User profile commands
Modern System i reports using Client Access
Tips for installing Lotus Domino server on a System i partition
The iSeries Blog has a new home on IT Knowledge Exchange
Virtualization for IBM i: Backups

Systems Management
Can you trust all those trigger programs?
Are your backups complete?
Controlling remote command processing
Watch your profiles
Avoid locking issues
Send message to users at a remote site
Security journal receiver management
Top 10 backup commands
Tracking critical file access in real time
Create an iSeries Access image and update it with the latest Service Pack

FTP
How to view source files in the library
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
Generically send a text file from the IFS via FTP
Automate Client Access to find files on Windows scheduler
SAVF by FTP on AS/400 -- error "source file not found"
Use a virtual directory to move a .bmp file from the IFS to a remote server to run a software package
Transferring binary files to IFS from a PC via FTP
FTP from AS/400 to PC folder
How to FTP without knowing the file name
IFS folder error

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts