ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Any program to FTP all the source members from specific library/source physical file?

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

  • Any program to FTP all the source members from specific library/source physical file?

    Hi,

    is there any IBM API /Utility available which could transfer the source members from a specific library/source physical file to desktop or to a given folder on local desktop or to a specific path like onedrive Or any shared drive etc.?
    How about below program ?

    Code:
    /COPY QCOPYSRC,P.H
    
    DCL &LIBRARY_NAME *CHAR 10 ;
    DCL &SOURCE_PHYSICAL_FILE *CHAR 10 ;
    DCL &REMOTE_HOST *CHAR 15 ;
    DCL &REMOTE_PORT *DEC (5 0) ;
    DCL &LOCAL_DIRECTORY *CHAR 100 ;
    
    DCL-S MemberList Char(50) Dim(100) ; // Array to hold member names
    
    DCL-PR GetMemberList ExtPgm('QUSLMBR') ;
    Receiver LikeDS(QUSLMBR) ;
    ReceiverLen Int(10) Const ;
    Format Char(8) Const ;
    QualifiedFileName Char(20) Const ;
    Member Char(10) Const ;
    Attribute Char(10) Const ;
    Error LikeDS(QUSLMBR) ;
    ErrorCode Char(7) ;
    End-PR ;
    
    DCL-PR DownloadMember ExtPgm('QSYS/QFTPCMD') ;
    Command Char(200) ;
    Length Int(10) ;
    Error LikeDS(QUSLMBR) ;
    ErrorCode Char(7) ;
    End-PR ;
    
    DCL-DS QUSLMBR ;
    Offset Int(10) ;
    KeyFields Char(20) ;
    Length Int(10) ;
    Text Char(50) ;
    Type Char(10) ;
    Attribute Char(10) ;
    Date Char(7) ;
    Time Char(6) ;
    File Char(10) ;
    Library Char(10) ;
    Member Char(10) ;
    End-DS ;
    
    /FREE
    // FTP connection information
    ConnectionInfo.HostName = &REMOTE_HOST ;
    ConnectionInfo.UserName = 'YOUR_USERNAME';
    ConnectionInfo.Password = 'YOUR_PASSWORD';
    ConnectionInfo.RemoteDir = '/YOUR/REMOTE/DIRECTORY';
    
    // Get the list of source members
    GetMemberList(QUSLMBR:%size(QUSLMBR):'MBRL0200':%t rim(&LIBRARY_NAME + '/' + &SOURCE_PHYSICAL_FILE):'*ALL':'*ALL':QUSLMBR:QCDET CDE);
    
    // Loop through the member list and download each member
    For I = 1 to QUSLMBR.Length;
    If %Len(QUSLMBR.Member(I)) > 0;
    // Construct the FTP command to download the member
    Command = 'LCD ' + &LOCAL_DIRECTORY + ' && CD ' + ConnectionInfo.RemoteDir +
    ' && GET ' + QUSLMBR.Member(I) + ' && CD /QSYS.LIB/' +
    %trim(&LIBRARY_NAME) + '.LIB/' + %trim(&SOURCE_PHYSICAL_FILE) + '.FILE';
    
    // Download the member using FTP
    DownloadMember(Command:%len(Command):QUSLMBR:QCDET CDE);
    EndIf;
    EndFor;
    
    // Inform the user that the download is complete
    DSPLY 'Source members downloaded successfully to your desktop.';
    *INLR = *ON;
    /END-FREE
    
    ​
    How about not prompting IP address and user id and password each time here?


    Thanks
Working...
X