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.

Related Posts
DB2 for i SQL – String Manipulation – POSSTR-LOCATE-LOCATE_IN_STRING (EN)

Introduction Often, in our applications, we need to work with text strings, and DB2 SQL can come in very useful Read more

DB2 for i – FAQ & Howtos (EN)

DB2 Database and SQL ... maybe the most important things on IBM i platform: here's a collection of FAQs, tips Read more

IBM i 7.4 Announcement (En)

Comes directly with the Easter egg this IBM announcement for the news of the IBM i 7.4 version, iNext version Read more

Generated Always Columns (EN)

Introduction "Generated Always Column": are columns, table fields, filled by DB2 engine: something like columns with a default value but Read more

Recent Posts

IBM i: System Management is Simpler Than You Think

If you work with IBM i, I recommend reading this insightful article by Giancarlo Lui: IBM i System Management: Simpler…

3 months ago

RPG Free and option(*convert) for paramters

In his recent article "RPG Free and option *convert" , Aldo Succi explores the *CONVERT option in the RPG language,…

3 months ago

CA Certificate Update for the European Central Bank (ECB): A Practical Guide

Updating Java and DCM Certificates for ECB Exchange Rate Retrieval on IBM i In our blog, we have previously discussed…

3 months ago

Managing Locked Display Files on IBM i: An Effective Solution

We are pleased to receive and share this "tip & trick" from Patrick Rizzi, which introduces a technique that allows…

6 months ago

Monitoring QSYSOPR Messages: SQL to Retrieve Messages and Replies

I take inspiration from a response by Michael Mayer on the Midrange.com mailing lists to someone who asked how to…

6 months ago

Why ERP is the Key to Success for Modern Businesses

Businesses are increasingly seeking tools to enhance efficiency, collaboration, and resource management. Enterprise Resource Planning (ERP) systems provide a comprehensive…

8 months ago