ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Appending date to filename during FTP.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Appending date to filename during FTP.

    Hi guys,

    I am trying to FTP a file from AS400 and for that I used INPUT/OUTPUT traditional FTP command from CL program.

    As of now I am running a RPG to create ftp input script everytime the program runs, so that I can append current date to the filename.
    One can use %DATE/:=% on windows FTP client and it works fine which means no recreating the script, something similar exists in AS400? Thanks.
    *...1....+....2....+....3....+....4....+....5....+ ....6....+....7.......+....8.......+....9.......+. ...10.......+....11...
    C*There are only 10 type of people in this world, those who understand binary and those who don't.

  • #2
    Re: Appending date to filename during FTP.

    ftpfilename = 'F' + %char(%date());
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Appending date to filename during FTP.

      I think you can even do %Char(%Dec(%Date())) if you don't want the separators.
      Ben

      Comment


      • #4
        Re: Appending date to filename during FTP.

        Ben, Always a pleasure....Are we as a collective whole gonna have fish tonight...It's Friday!
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Appending date to filename during FTP.

          I'm afraid I'm going out for a meal tonight. It's an Italian restaurant so fish and chips is unlikely.
          Ben

          Comment


          • #6
            Re: Appending date to filename during FTP.

            Booooooo!
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Appending date to filename during FTP.

              I'm gonna pull out the Smoker and do a Beer-Butt Chicken (Shove a beer can up it's butt and season it). That plus some smoked veggies should prove for a nice night in with our 74* weather... I'm thinking Alcohol might be a factor as well!

              Comment


              • #8
                Re: Appending date to filename during FTP.

                That sounds equally enticing ..... But is trumped by the whole -- eating it in the UK thing..
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #9
                  Re: Appending date to filename during FTP.

                  Originally posted by BenThurley View Post
                  I think you can even do %Char(%Dec(%Date())) if you don't want the separators.
                  %char(%date():*dmy0);
                  The 0 after the dmy indicates no seperators.
                  Regards

                  Kit
                  http://www.ecofitonline.com
                  DeskfIT - ChangefIT - XrefIT
                  ___________________________________
                  There are only 3 kinds of people -
                  Those that can count and those that can't.

                  Comment


                  • #10
                    Re: Appending date to filename during FTP.

                    Hi Guys,

                    Thanks for the input, but this is not what I am looking for. I am already using RPG functions in the RPG program that re-writes the script everytime. Is there a way I can put some thing in the script itself so that I don't have to recreate it every day?

                    As of now my RPG program writes a new put command every day with current date appended to the file name. Are there any date functions that run on FTP client?
                    Like in a dos batch program if I use below command to FTP file I do not have to recreate the batch file again for next day.

                    PUT MYFILE \NETWORK\PATH\MYFILE_%DATE/:=%.csv

                    This will take care of the date for all runs.

                    However right now I do a CLRPFM on FTP input member and rewrite the put command with current date appended.

                    Btw I don't want the separators Need CYYMMDD
                    *...1....+....2....+....3....+....4....+....5....+ ....6....+....7.......+....8.......+....9.......+. ...10.......+....11...
                    C*There are only 10 type of people in this world, those who understand binary and those who don't.

                    Comment


                    • #11
                      Re: Appending date to filename during FTP.

                      No there is no to do what you want on the PUT...(use Kits example - %char(%date():*cymd0);
                      We all re-write the input file for sending, I use SQL and a temp global file for my input..
                      Why is this an issue for you?
                      All my answers were extracted from the "Big Dummy's Guide to the As400"
                      and I take no responsibility for any of them.

                      www.code400.com

                      Comment


                      • #12
                        Re: Appending date to filename during FTP.

                        It's not an issue, I just get rid of an extra module, that's all. When I saw it's possible in MS DOS I thought something similar must exist in AS400...

                        But it's ok, I will make do with RPG program then.
                        Just out of curiousity, if you have a temporary global file, don't you have to recompile everything whenever you add members to it? Or adding members do not give level check? (I have been recently haunted by this level check so much that I can't help asking!)

                        Thanks.
                        *...1....+....2....+....3....+....4....+....5....+ ....6....+....7.......+....8.......+....9.......+. ...10.......+....11...
                        C*There are only 10 type of people in this world, those who understand binary and those who don't.

                        Comment


                        • #13
                          Re: Appending date to filename during FTP.

                          Originally posted by Prototype View Post
                          It's not an issue, I just get rid of an extra module, that's all. When I saw it's possible in MS DOS I thought something similar must exist in AS400...

                          But it's ok, I will make do with RPG program then.
                          Just out of curiousity, if you have a temporary global file, don't you have to recompile everything whenever you add members to it? Or adding members do not give level check? (I have been recently haunted by this level check so much that I can't help asking!)

                          Thanks.
                          what's the big deal about doing it in RPG to begin with? you said you were using an RPG program to write the input for the script file??? if you're talking about a "temporary global file" as in created with SQL i'm not sure what you're actually gaining here. as far as level checking goes, you can either OVRDBF to the script file using LVLCHK(*NO) this is NOT my preference, create a "template" file in a permanent library & CRTDUPOBJ into QTEMP. if you've compiled over the "template" file you wouldn't get a level check with the CRTDUPOBJ.
                          I'm not anti-social, I just don't like people -Tommy Holden

                          Comment


                          • #14
                            Re: Appending date to filename during FTP.

                            PHP Code:
                                  *=======================================================================                      
                                  * 
                            PROGRAM ##FTP                                                                             
                                  
                            PURPOSE FTP to a server get a list of files and retrive them                              
                                  
                            WRITTEN -                                                                                   
                                  * 
                            AUTHOR  -                                                                                   
                                  *                                                                                             
                                  *=======================================================================                      
                                 
                            d cmdstring       s           2000                                                             
                                 d cmdlength       s             15  5                                                          
                                 d ftpdata         s            100                                                             
                                 d Q               s              1    inz
                            ('''')                                                
                                 
                            d remoteIP        s             15    inz('XX.X.X.XX')                                         
                                 
                            d sqlstmt         s          23000    varying                                                  
                                                                                                                                
                                 d openList        pr                                                                           
                                 d FetchNext       pr              n                                                            
                                 d closeList       pr                                                                           
                                                                                                                                
                                  
                            // external calls                                                                             
                                 
                            d $command        pr                  extpgm'QCMDEXC' )                                      
                                 
                            d   cmdstring                 2000    options( *varsize ) const                                
                                 
                            d   cmdlength                   15  5                     const                                
                                                                                                                                
                                  /
                            free                                                                                         
                                                                                                                                
                                     exsr $ftplist
                            ;                                                                             
                                     
                            exsr $readList;                                                                            
                                                                                                                                
                                     *
                            inlr = *on;                                                                               
                                                                                                                                
                                    
                            //-------------------------------------------                                               
                                    // $ftpList - List the directory contents to                                                
                                    //            a table DIROUTPUT.                                                            
                                    //                                                                                          
                                    // if it doesnt exist system creates if there                                               
                                    // then member is *Replaced..                                                               
                                    //-------------------------------------------                                               
                                         
                            begsr $ftpList;                                                                        
                                                                                                                                
                                             
                            // now copy the file to the IFS                                                    
                                                                                                                                
                                          
                            cmdstring 'CPYTOIMPF FROMFILE(QTEMP/SLS28WORKP) ' +                                 
                                                      
                            ' TOSTMF(' '/home/sls28/sls28.csv' +                                
                                                      
                            ') ' +                                                                
                                                      
                            'STMFCODPAG(*PCASCII) ' +                                                 
                                                      
                            'RCDDLM(*CRLF) STRDLM(*NONE) MBROPT(*REPLACE)';                           
                                          
                            cmdlength = %len(%trim(cmdstring));                                                   
                                          
                            monitor;                                                                              
                                          
                            $command(cmdstring cmdlength);                                                      
                                          
                            on-error;                                                                             
                                          
                            endmon;                                                                               
                                                                                                                                
                                                                                                                                
                                         
                            //prepare the FTP                                                                      
                                                                                                                                
                                         //in case this is a repeat delete the overrides and                                    
                                         //the input output file(s)                                                             
                                                                                                                                
                                         
                            cmdstring 'DLTOVR INPUT';                                                            
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'DLTOVR OUTPUT';                                                           
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'DLTF FILE(QTEMP/INPUT)';                                                  
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'DLTF FILE(QTEMP/OUTPUT)';                                                 
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'CRTPF FILE(QTEMP/INPUT) ' +                                               
                                                      
                            ' RCDLEN(256)';                                                           
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'CRTPF FILE(QTEMP/OUTPUT) ' +                                              
                                                      
                            ' RCDLEN(256)';                                                           
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                          
                            // populate the input file                                                            
                                                                                                                                
                                                                                                                                
                                     
                            Exec SQL   INSERT INTO INPUT                                                               
                                                values
                            ('&user  &password');                                                     
                                                                                                                                
                                     
                            Exec SQL   INSERT INTO INPUT                                                               
                                                values
                            ('dir (DISK ');                                                           
                                                                                                                                
                                                                                                                                
                                     
                            Exec SQL   INSERT INTO INPUT                                                               
                                                values
                            ('quit');                                                                 
                                                                                                                                
                                         
                            cmdstring 'OVRDBF FILE(INPUT) TOFILE(QTEMP/INPUT)' +                                 
                                                     
                            ' OVRSCOPE(*JOB) ';                                                        
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'OVRDBF FILE(OUTPUT) TOFILE(QTEMP/OUTPUT)' +                               
                                                     
                            ' OVRSCOPE(*JOB) ';                                                        
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            cmdstring 'STRTCPFTP ' + %trim(remoteIp)  + Q  ;                                 
                                         
                            cmdlength = %len(%trim(cmdstring));                                                    
                                         
                            monitor;                                                                               
                                         
                            $command(cmdstring cmdlength);                                                       
                                         
                            on-error;                                                                              
                                         
                            endmon;                                                                                
                                                                                                                                
                                         
                            endsr;                                                                                 
                                                                                                                                
                                    
                            //-------------------------------------------                                               
                                    // $readList - read the list created                                                        
                                    //-------------------------------------------                                               
                                                                                                                                
                                         
                            begsr $readList;                                                                       
                                                                                                                                
                                          
                            sqlstmt 'select * from DIROUTPUT ';                                                 
                                          
                            openList();                                                                           
                                          
                            dow fetchNext();                                                                      
                                                                                                                                
                                         
                            //   file date              1      8                                                   
                                         //   file time             11     17                                                   
                                         //   date&time              1     17                                                   
                                         //   isdirectory           25     29                                                   
                                         //   file size             29     38                                                   
                                         //   file name             40     89                                                   
                                         //   .....                 49     98                                                   
                                                                                                                                
                                                                                                                                
                                                                                                                                
                                           
                            dsply %subst(ftpdata:40:25' ';                                                     
                                                                                                                                
                                          
                            enddo;                                                                                
                                          
                            closeList();                                                                          
                                                                                                                                
                                                                                                                                
                                         
                            endsr;                                                                                 
                                                                                                                                
                                    
                            //-------------------------------------------                                               
                                  
                            /end-free                                                                                     
                                                                                                                                
                                  
                            *--------------------------------------------------------                                     
                                  *  
                            openList  Open a cursor to read file                                                     
                                  
                            *--------------------------------------------------------                                     
                                 
                            p openList        b                                                                            
                                                                                                                                
                                 d openList        pi                                                                           
                                                                                                                                
                                  
                            /Free                                                                                         
                                                                                                                                
                                   exec sql                                                                                     
                                    
                            declare MyCursor cursor for statement;                                                      
                                                                                                                                
                                   
                            exec sql                                                                                     
                                    prepare statement from 
                            :sqlstmt;                                                            
                                                                                                                                
                                   
                            exec sql                                                                                     
                                    open mycursor
                            ;                                                                              
                                                                                                                                
                                  /
                            End-Free                                                                                     
                                                                                                                                
                                 p openList        e                                                                            
                                  
                            *--------------------------------------------------------                                     
                                  *  
                            fetchNext  read one record at a time                                                     
                                  
                            *--------------------------------------------------------                                     
                                 
                            p fetchNext       b                                                                            
                                                                                                                                
                                 d fetchNext       pi              n                                                            
                                                                                                                                
                                  
                            /free                                                                                         
                                                                                                                                
                                   exec sql                                                                                     
                                    fetch next from mycursor into 
                            ftpdata;                                                    
                                     if 
                            sqlstt '02000';                                                                       
                                       return *
                            on;                                                                              
                                     else;                                                                                      
                                       return *
                            off;                                                                             
                                     endif;                                                                                     
                                                                                                                                
                                  /
                            end-free                                                                                     
                                                                                                                                
                                 p fetchNext       e                                                                            
                                  
                            *--------------------------------------------------------                                     
                                  *  
                            closeOrderList  Close the OrderHdr cursor                                                
                                  
                            *--------------------------------------------------------                                     
                                 
                            p closeList       b                                                                            
                                                                                                                                
                                 d closeList       pi                                                                           
                                                                                                                                
                                  
                            /free                                                                                         
                                                                                                                                
                                   exec sql                                                                                     
                                    close MyCursor
                            ;                                                                             
                                                                                                                                
                                  /
                            end-free                                                                                     
                                                                                                                                
                                 p closeList       e 
                            All my answers were extracted from the "Big Dummy's Guide to the As400"
                            and I take no responsibility for any of them.

                            www.code400.com

                            Comment


                            • #15
                              Re: Appending date to filename during FTP.

                              Originally posted by tomholden View Post
                              create a "template" file in a permanent library & CRTDUPOBJ into QTEMP. if you've compiled over the "template" file you wouldn't get a level check with the CRTDUPOBJ.
                              Fair enough. Thanks.

                              As of now I have one single file and I add different members for different extracts/reports, one for input and one for output and do overrides. Not one of the best approaches I guess.

                              I will try a global template and duplicate it for different purposes in future.
                              *...1....+....2....+....3....+....4....+....5....+ ....6....+....7.......+....8.......+....9.......+. ...10.......+....11...
                              C*There are only 10 type of people in this world, those who understand binary and those who don't.

                              Comment

                              Working...
                              X