sponsored links

Collapse

Announcement

Collapse
No announcement yet.

FTP Question

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

  • jamief
    replied
    Re: FTP Question

    This is why the solution I gave you is much better....
    from linux server directly to IFS.

    jamie

    Leave a comment:


  • Scott Klement
    replied
    Re: FTP Question

    You are telling it FTP to create a file with a member named "0bte0l007dmdqvg80000qvp1_39", but a member name can only be 10 characters long.

    Leave a comment:


  • Gary B
    replied
    Re: FTP Question

    Hi guys,

    I continue to have problems trying to pick up files from a server.

    Below is the session and the name of the file I am getting seems to be a problem.

    Thanks again for any assistance you can lend.

    Gary Barnes

    Connecting to host AS3.BETAGRID.GXS.COM at address 204.90.130.34 using port 6899.
    220 Service ready for new user.
    > lepco378ftp
    331 User name okay, need password for lepco378ftp.
    230 User logged in, proceed.
    UNIX Type: Apache FtpServer
    > cd /././POLLABLE
    250 Directory changed to /lepcoftp/././POLLABLE
    > get 0203apda.tdf.000030502.0bte0l007dmdqvg80000qvp1_39 fece007ekes
    Specified object name too long: t.0bte0l007d.

    Leave a comment:


  • Gary B
    replied
    Re: FTP Question

    Yes I did. I searched out the answer, which I should have done before I posted.

    I've been down this path before but I do this so infrequently that I had forgot this step.

    Leave a comment:


  • jamief
    replied
    Re: FTP Question

    cool....
    did you do this as first executable line of code?
    PHP Code:
    exec sql  set option commit=*none,datfmt=*iso 
    Don't yell at me if you delete server files

    Leave a comment:


  • Gary B
    replied
    Re: FTP Question

    Never mind, I have it.

    Leave a comment:


  • Gary B
    replied
    Re: FTP Question

    Jamie,

    I use SQL quite a bit, mostly for fetching, and am not much of an expert.
    Why would I be getting the error below when I try to INSERT into INPUT.

    Thanks,
    Gary

    Member INPUT not journaled to journal *N.
    INPUT in QTEMP not valid for operation.

    Leave a comment:


  • Gary B
    replied
    Re: FTP Question

    Thanks Jamie!

    I'll report back on my success.

    Gary

    Leave a comment:


  • jamief
    replied
    Re: FTP Question

    I use this to list files on a server and copies them to IFS on IBMi
    be careful when testing it deletes the server copy!
    PHP Code:
          *=======================================================================                      
          *                                                                                             
          * 
    PROGRAM SIG001                                                                            
          
    PURPOSE Program grabs .csv documents from server lbi-13                                   
          
    *           copies them to the IFS /sigmanest/neststhen deletes                             
          
    *           them from the server                                                              
          
    WRITTEN 06/01/2012                                                                        
          
    AUTHOR  jamie flanary                                                                     
                                                                                                        
          
    AUTHORITY PARAMETERS                                                                        
          
    *   Description                      How Used                                                 
          
    *   -----------                      --------                                                 
                                                                                                        
          * 
    PROGRAM DESCRIPTION                                                                         
          
    *   This program will grab .csv documents from server then copy to IFS delete               
          
    *                                                                                             
          * 
    INDICATOR USAGE                                                                             
          
    *   03 leave current screen                                                                 
          
    *                                                                                             
          *=======================================================================                      
         
    d cmdstring       s           2000                                                             
         d cmdlength       s             15  5                                                          
         d DataString      s            100                                                             
         d ftpdata         s            100                                                             
         d IseriesFolder   s            256    inz
    ('/sigmanest/nests/')                                 
         
    d mode            s              1                                                             
         d Password        s             10    inz
    ('serverpassword')                                           
         
    d Q               s              1    inz('''')                                                
         
    d remoteIP        s             15    inz('10.0.1.52')                                         
         
    d sqlstmt         s          23000    varying                                                  
         d Userid          s             10    inz
    ('serverid')                                           
                                                                                                        
         
    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                                                                                         
                                                                                                        
             mode 
    '1';                                                                                
                                                                                                        
             
    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;                                                                        
                                                                                                        
                 
    //prepare the FTP                                                                      
                 //in case this is a repeat delete the overrides and                                    
                 //the input output file(s)                                                             
                                                                                                        
                 
    cmdstring 'DLTOVR FILE(DIROUTPUT) LVL(*)';                                           
                 
    cmdlength = %len(%trim(cmdstring));                                                    
                 
    monitor;                                                                               
                 
    $command(cmdstring cmdlength);                                                       
                 
    on-error;                                                                              
                 
    endmon;                                                                                
                                                                                                        
                 
    cmdstring 'DLTF QTEMP/DIROUTPUT';                                                    
                 
    cmdlength = %len(%trim(cmdstring));                                                    
                 
    monitor;                                                                               
                 
    $command(cmdstring cmdlength);                                                       
                 
    on-error;                                                                              
                 
    endmon;                                                                                
                                                                                                        
                 
    cmdstring 'CRTPF QTEMP/DIROUTPUT RCDLEN(256)';                                       
                 
    cmdlength = %len(%trim(cmdstring));                                                    
                 
    monitor;                                                                               
                 
    $command(cmdstring cmdlength);                                                       
                 
    on-error;                                                                              
                 
    endmon;                                                                                
                                                                                                        
                 
    cmdstring 'OVRDBF FILE(DIROUTPUT) TOFILE(QTEMP/DIROUTPUT)' +                         
                             
    ' OVRSCOPE(*CALLLVL)';                                                     
                 
    cmdlength = %len(%trim(cmdstring));                                                    
                 
    monitor;                                                                               
                 
    $command(cmdstring cmdlength);                                                       
                 
    on-error;                                                                              
                 
    endmon;                                                                                
                                                                                                        
                 
    cmdstring 'DLTOVR INPUT LVL(*)';                                                     
                 
    cmdlength = %len(%trim(cmdstring));                                                    
                 
    monitor;                                                                               
                 
    $command(cmdstring cmdlength);                                                       
                 
    on-error;                                                                              
                 
    endmon;                                                                                
                                                                                                        
                 
    cmdstring 'DLTOVR OUTPUT LVL(*)';                                                    
                 
    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;                                                                                
                                                                                                        
                 
    // depend on process what commands can be entered                                      
                 
    select;                                                                                
                  
    when Mode '1';                                                                      
                   
    // populate the input file                                                           
                   
    datastring = %trim(Userid) + '   ' + %trim(Password);                                
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    (:dataString);                                                           
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    ('cd \ereport');                                                         
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    ('dir (DISK ');                                                          
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    ('quit');                                                                
                                                                                                        
                  
    when Mode '2';                                                                      
                   
    // populate the input file                                                           
                   
    datastring = %trim(Userid) + '   ' + %trim(Password);                                
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    (:dataString);                                                           
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    ('bin');                                                                 
                                                                                                        
                   
    datastring 'namefmt 1';                                                            
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    (:dataString);                                                           
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    ('cd  \ereport');                                                        
                                                                                                        
                   
    datastring 'get   ' + %trim(%subst(ftpdata:40:25)) + '  ' +                        
                                %
    trim(IseriesFolder)  +                                                 
                                %
    trim(%subst(ftpdata:40:25)) + '  ' +                                   
                                
    ' (replace';                                                            
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    (:dataString);                                                           
                                                                                                        
                   
    datastring 'dele ' + %trim(%subst(ftpdata:40:25));                                 
                   
    Exec SQL   INSERT INTO INPUT                                                         
                         values
    (:dataString);                                                           
                 
    endsl;                                                                                 
                                                                                                        
                 
    cmdstring 'OVRDBF FILE(INPUT) TOFILE(QTEMP/INPUT)' +                                 
                             
    ' OVRSCOPE(*CALLLVL)';                                                     
                 
    cmdlength = %len(%trim(cmdstring));                                                    
                 
    monitor;                                                                               
                 
    $command(cmdstring cmdlength);                                                       
                 
    on-error;                                                                              
                 
    endmon;                                                                                
                                                                                                        
                 
    cmdstring 'OVRDBF FILE(OUTPUT) TOFILE(QTEMP/OUTPUT)' +                               
                             
    ' OVRSCOPE(*CALLLVL)';                                                     
                 
    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 QTEMP/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                                                   
                   
    if %scan('.CSV' :%subst(ftpdata:40:25)) > *zeros;                                    
                    
    mode '2';                                                                         
                    
    exsr $ftplist;                                                                      
                   endif;                                                                               
                  
    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 
    Attached Files

    Leave a comment:


  • Gary B
    replied
    Re: FTP Question

    Scott,
    I was afraid this might be the case.
    I'll probably be back for more information after I've had time to work on this approach.
    Thanks so much for the input.
    Gary

    Leave a comment:


  • Scott Klement
    replied
    Re: FTP Question

    Hi Gary,

    Unless I'm much mistaken, you cannot use a wildcard on the GET subcommand. If you could, however, the way you've coded it would not work as desired -- it'd replace QTEMP/MYFILE for each file downloaded, the effect of which would be that only the last file would be in QTEMP/MYFILE (since it would've replaced the prior one.)

    May I suggest a different strategy?
    • Create a temporary directory in the IFS. If you're able to write a program, the IBM-supplied tmpnam() API can create a unique name that's unique.
    • Build an FTP script (on-the-fly) that uses the MGET FTP subcommand to download all files (using a wildcard) to the temporary IFS directory.
    • After FTP is successful, combine the files in the IFS directory (QShell could do this easily) into a PF in your desired library.
    • Delete the temporary IFS directory, and it's contents.


    I'd be happy to provide further details on any of these steps, if needed.

    Leave a comment:


  • Gary B
    started a topic FTP Question

    FTP Question

    Merry Christmas everyone!

    I have an FTP situation I've not run into before and cannot find anything on this anywhere.

    I need to pick up multiple files from a remote server (not an i).
    I do not know the file names and the names will never be the same name.
    I'd like all the data from all the files to go into 1 i file.
    The data format will always be the same for every file.

    I'm hoping someone can help with these questions;

    1. Is the proper format of the FTP command 'GET * QTEMP/MYFILE (REPLACE'

    2. Will all the data from all the files received be put into qtemp/myfile?

    Thanks all,
    Gary
Working...
X