01 - Programming (EN)01e - Programming miscellanea (EN)

STRTCPFTP how to use it to run fast FTP

We often find ourselves sharing files and information via FTP.
Several applications make FTP areas available to file xml, txt and more.
In the Supply Chain, for example, connections are made available via FTP to perform download and upload of Xml, Txt or Csv files to exchange information to be treated with proprietary ERPs or in agent management processes to synchronize Ftp catalogs, orders and anything else with the tools available to the sales force. In this article we see how to make a transfer FTP, which allows you to quickly send even large files (… giga byte)

This method can be used to perform rescues on an external nas disk, located in your network, transferring * Savf objects from the Ibm-I asp to the Ftp location available. In the example below, we describe how to transfer * Savf objects from Ibm-I to a FTP area of the corporate or external intranet. The same process can be easily replicated to perform sending and receiving functions of any object negotiable with Ftp.

Introduction

We generate a simple full free rpg application that writes the commands to a temporary source file which we call FTPCMD with FTP member. The application reads the “SALVA_FTP” table which contains the libraries that will be saved as savf.
The written commands are typical of Ftp: user, password, BIN, PUT, GET, QUOTE, ….

CREATE TABLE LIBRERIA.SALVA_FTP (
                LIBRARY CHAR (10) CCSID 280 NOT NULL DEFAULT '')  
                RCDFMT SALVA_FTP;     
// ************************************************ ****
// PGM: FTP01
// command to execute to compile the pgm: 
// CRTSRCPF FILE (LIBRARY / FTPCMD) RCDLEN (100) MBR (FTP)
// ************************************************ ****
  
CTL-Opt OPTION (SRCSTMT: NODEBUGIO)                       
 DFTACTGRP (No);                                           
 dcl-f save_ftp usage (input) rename (save_ftp: save)
 dcl-f ftpcmd usage (* output) rename (ftpcmd: ftprec);             

 dcl-s userf2 char (10);                                
 dcl-s passf2 char (10);                                
 
   dcl-ds CmdRec;                                     
      srcseq packed (6: 2);                               
      SRCDAT packed (6: 0);                              
      SRCDTA char (88);                                   
   END-SD;                                            

         userf2 = 'qpgmr01'; // user record and password                             
         passf2 = 'qpgmr01';                 
         srcdta = userf2 + passf2;                      
         srcdat = 0;                                   
         srcseq = + 1;                                   
         write ftprec;                           

         srcseq = + 1;                                   
         srcdta = 'BIN'; // BIN record                     
         write ftprec;                          

         dow not (% eof);                              
          read save_ftp; // read table                      
           if% eof;                           
           leave;                                
           endif;                                 
           srcseq = + 1;                                 
           srcdta = 'PUT' + 'QGPL /' + // BIN record                  
                 % TRIM (LIBRARY);                    
           write ftprec;                       
          enddo;                                    

          * * INLR = On; 

Launch of the STRTCPFTP command

I execute in a clle the commands for updating the tables in the qtemp.
The FTPCMD table will contain the FTP commands generated by the application of the previous point.
The FTPLOG table will contain the log of the executed transactions.

The STRTCPFTP command will be launched with the parameter indicating the FTP location which will be accessed with the user and password memorized by the function described above.

/ * FTP_CL * /

PGM PARM (& TGTSYS) / * parameter containing the ftp address of destination ftp.xxxx.xx * /
DCL VAR (& TGTSYS) TYPE (* CHAR) LEN (30)        
DLTF FILE (QTEMP / FTPCMD)      
MONMSG MSGID (CPF2105)          

CRTSRCPF FILE (QTEMP / FTPCMD) RCDLEN (100) MBR (FTP)       
OVRDBF FILE (FTPCMD) TOFILE (QTEMP / FTPCMD) MBR (FTP)    

CALL PGM (FTP01)                                    

DLTF FILE (QTEMP / FTPLOG)                   
MONMSG MSGID (CPF0000)                                 
CRTPF FILE (QTEMP / FTPLOG) RCDLEN (132) MBR (FTPLOG)    
OVRDBF FILE (INPUT) TOFILE (QTEMP / FTPCMD) MBR (FTP)     
OVRDBF FILE (OUTPUT) TOFILE (QTEMP / FTPLOG) MBR (FTPLOG) 

STRTCPFTP RMTSYS (& TGTSYS)          
 
DLTOVR FILE (* ALL)                                                                                           

Final Application

And here is the final launch that includes saving the libraries inserted in the table and sending ftp to the savf

/ * SAVE_CL * /

PGM                                                       

DCLF FILE (LIBL / SALVA_FTP)                                        
DCL VAR (& LIBRARY) TYPE (CHAR) LEN (10)             
  / ** save libraries on Iseries disk                                
LOOP: RcvF                                                                     

MonMsg MsgId (CPF0864) Exec (GoTo EOF)                               
CRTSAVF FILE (& LIBRARY)                                              
MONMSG MSGID (CPF5813 CPF7302)                                       

SAVLIB LIB (& LIBRERIA) DEV (SAVF) SAVF (& LIBRARY) +   
                            CLEAR (ALL) SAVACT (SYSDFN) DTACPR (MEDIUM)                
MONMSG MSGID (CPF9812)                                               
GOTO CMDLBL (LOOP)                                         
EOF:     
                                                         
 / * ftp of savf on nas * /                 
 CALL FTP_CL ('xxx.xxx.xxx.xxx)                                         

Log

Example of the log stored in the table qtemp / ftplog .
…………….>
PUT QGPL / LIBRARY
229 Entering Extended Passive Mode (!!! 24775!).
150 Sending file to member LIBRARY in LIBRARY file in QGPL library. 
226 File transfer completed successfully 2
2176 bytes transferred in 0.062 seconds. Transfer speed 354,816 KB / sec.

….

Conclusions

The described technique allows to write fast, structured and brilliant applications to send and receive information via ftp for the IBM-I platform.

About author

Project manager, business management consultant, application development with Rpgfree, Python, JavaScript. I entered the IT world when the As400 was born, I am a supporter of the Ibm-I platform and its enormous potential and I believe in the resources offered by the community by open source. I am grateful to collaborate with FAQ400 because I fully share the objectives.

Leave a Reply

%d bloggers like this: