ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

ZIP in IFS created for more files generated.

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

  • ZIP in IFS created for more files generated.

    Hi,
    I have to make an archive with some files xml who will be generated in a folder in IFS, - the xml files will be setup to be stored in IFS, the same thing should be done for the ZIP file.
    can you help me with some ideas how it is possible to create an archive with all the XML files. This archive myarchive.zip will be transfered via SFTP or CFT to another machine. For now I don't know how can I generate the archive and how can I make the compression for all the files who will be generated.
    Thanks in advance

  • #2
    Look at the Open Source ZLIB project. https://github.com/ChrisHird/ZLIB

    Comment


    • #3
      Also if you are installing the IBM OPen Source options see the following.

      Comment


      • #4
        Can you provide me an example, with what commands or something like this, can I create the file as .ZIP file in the IFS? - briefly I have more files - streamfiles- generated in a folder in IFS with extension .XML - and I have to make an archive with them

        Comment


        • #5
          It is possible to make the compression for more streamfiles with QSH commands?
          My goal is to make an archive .ZIP for more files generated in IFS, the archive must be in a folder in IFS and after to transfer this archive to a Windows folder. - or directly it is possible to create this archive in a Windows folder

          Comment


          • #6
            You can use java to create zip files in a directory in the /root filesystem. Have a look at the jar command. The syntax is something like:
            jar cfM <directory/zip file name> <stmf to zip>
            You can search the internet for all the parameters for the jar command.

            Comment


            • #7
              Both the InfoZip and 7-Zip tools can be made to run in PASE and called from QShell. These work perfectly for making Zip files on IBM i.

              1) Here's an article on InfoZip (the code examples are screwed up, but look better if you click on the "Print" friendly version):
              Read through for news and resources on software development topics, including low-code-no-code, serverless computing and programming languages.


              2) Here's a similar article for 7-Zip. 7-Zip is cool because it supports a wide range of different formats, .ZIP is one of them, but GZip, TAR, BZ2, 7Z, etc are all supported, so its very versatile.
              Read through for news and resources on software development topics, including low-code-no-code, serverless computing and programming languages.


              3) You can also use the JAR tool as John.sev99 mentioned -- it only supports the most rudamentary features of .ZIP format, and is slow -- but might be "good enough" depending on your needs.

              4) The ZLIB tool mentioned by Chris Hird also works, and is a native port (as opposed to running in PASE) which is kinda nice, but is not nearly as versatile as InfoZip or 7-Zip. I haven't looked at Chris' implementation of ZLIB, but the one that Uzaemon distributed for a long time had big problems in that it had a single ASCII/EBCDIC translation table hard-coded into it, and assumed everyone used that particular translation table. (Which isn't true, there are many different flavors of EBCDIC that are all a little different.) Knowing Chris, he probably did a better job with his port, but I haven't looked at it.

              5) Finally, starting with V7R1, there are APIs built in to the OS that support zip. Since they are APIs, programming is required to use them (it's not a command you can run directly) but it is probably worth a look if you have a programmer on staff.



              So that's 5 different ways to do Zip/Unzip on IBM i. I'm sure one of them will work for you!

              Comment


              • chris_hird
                chris_hird commented
                Editing a comment
                Scott,

                For the open source list I put up I did not change the original code. Internally for our use I used the iconv() API to do the conversions :-) I should really add a new branch with the updates, but wanted others to get involved and contribute so have not got round to it yet.. I have also used the Qzipzip() API for IFS based compression and decompression, works very well and I am told its a better solution than the ZLIB stuff because of better algorithmns??? (I have no scientific facts to support that). If people want I could share the C code I used for testing the technology.

            • #8
              Hi, I just used the JAR tool,this is the command used in the QSHELL to zip more files:

              jar cvf /Myfolder/Myarchive/myArchive.zip /Myfolder/Myfiles/file1.xml /Myfolder/Myfiles/file2.xml

              In the IFS I have the following structure:

              Root -> Myfolder -> Myarchive (subfolder of Myfolder)
              Root-> Myfolder -> Myfiles (subfolder of Myfolder)


              myarchive.zip is created in the desired path with these 2 files but if I retrieve myarchive.zip on my PC I have a structure of folders like this:
              My/folder/Myarchive/file1.xml & file2.xml


              It is possible to have only myarhcive.zip with the files file1.xml and file2.xml inside? and not all the folders structure, similar to the IFS path?

              Comment


              • #9
                The jar command will incorporate the directory path you specify with your files into the archive so you will need to make the Myfiles directory your current directory before using the jar command:

                CD /Directory
                jar ... /Directory/Archive.zip File1 File2...

                Comment


                • #10
                  Oky, thanks, I tried on this way:
                  - if I make all the command in the QSHELL console all the things are alright and I can get the archive on my PC with FTP -> only myarchive.zip with 2 files xml inside - OK
                  -but.. if I put all the commands in a RPGLE program and I try to execute I have an error:
                  I made like this:
                  outfile = 'myarchive.zip';
                  infile = 'file1.xml file2.xml;

                  string = 'STRQSH CMD(' cd /home');
                  call 'QCMDEXC' with parm string

                  string = *blanks;
                  string ='STRQSH CMD(' cd /myfolder');
                  call 'QCMDEXC' with parm string

                  string = 'STRQSH CMD(''' jar cvf'
                  +%trim(outfile)+' '
                  +%trim(infile)+'''')';
                  call QCMDEXC with parm string

                  -> all the commands should be in the same Shell session - so I supposed it is ok because I do not close the session between the commands.
                  the last value of string variable before the last call is:
                  STRQSH CMD('jar cvf myarchive.zip file1.xml file2.xml') --> I have error at the file2.xml -> file2.xml: file or directory doesn't exist.

                  Comment


                  • #11
                    Every time you run STRQSH, you start a new shell session. Change it to something like:

                    Code:
                    string = 'STRQSH CMD(''cd /myfolder && '
                           + 'jar cvf '
                           + %trim(outfile) + ' '
                           + %trim(infile) + ''')';
                    This does the cd /myfolder followed by the jar in the same session.

                    Comment

                    Working...
                    X