ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

sFTP and continuation character

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

  • #31
    Interesting stuff. I am currently researching how to implement sFTP on the iSeries and although it seems it can be done, I don't think I have the time or patience to go through all of this. I think I would be be easier to use FileZilla to download to PC then upload to iSeries IFS.

    Robert it looks like this is an EDI implementation, I assume you would need to delete the files you retrieved from the remote server, that doesn't seem to be covered. Maybe I missed it though.

    Comment


    • #32
      Hi Jim,
      I guess it would be easier to download to PC then upload to the iSeries but that is a two step process. Since the goal was to get the file into the AS400 I thought it was an exercise worth pursuing. I have a lot of years on the iSeries and I actually volunteered to work on this. I love to learn new things and had never done shell scripts before so I jumped right in. I had to invest more time on it than I anticipated but with some invaluable tips from Scott Klement I was able to get it to work. As you can see from my posts, there really aren't very many lines of code involved.

      Regarding your question, yes I am grabbing EDI files. On the remote end they automatically archive the files once they are picked up. However, if I need to add a line to delete the files I will certainly do so. At this point that would be easy.





      Comment


      • #33
        IBM i uses the same OpenSSH software that's used on pretty much every other platform (Linux, MacOS, etc) it is the most widely used SSH software in the world. The learning curve is exactly the same no matter which platform you're on because it's the same software.

        Comment


        • #34
          I was hoping to get started on this but even the install of expect and tcl is a problem.

          So having downloaded the expect and tcl tar files to the /tmp directory in the IFS I tried the "uncompress expect.5.43.tar.Z" command (in QP2TERM) and was informed "no such file".
          Tried the command again omitting the "Z" something must have happened as I got no feedback, just the $ prompt.

          Looking at the /tmp directory, there is a file "expect.5.43.tar 4.89mb WinZip file.

          Executed command "tar xf /tmp/expect.5.43.tar" no feedback, slight delay then $ so maybe did something. I don't know what this command is doing. Unpacking/extracting I assume ? To where ?

          Command ln -s /qopensys/usr/bin/stty /usr/local/bin/stty yields "ln: A file or directory in the path name does not exist."

          Can anyone help/point me in the right direction as to how to install these programs ?

          Comment


          • #35
            I didn't realize that IBMi uses the same Open SSH software used on other platforms. I will be sure to remember that. I find it interesting that userid/password authentication is so widely used when public key authentication is more secure. When I first embarked on the mission to get SFTP working I contacted IBM and they referred me to the technical document N1012710. After skimming over it I thought it was going be relatively easy:

            Create a user profile designated for SSH related functions, call QP2TERM to enter the PASE environment, create a home directory, set permissions for the home directory and then create my public and private key pair. Then finally FTP the binary public key to my pc, attach to an email and send it over to the server administrator. I figured that once they had my public key I would be authenticated and good to go.

            I was certainly in for a surprise when I was told they had no use for my public key file. It was userid/password authentication or BUST. Then I found out about the freeware called Expect. I had reservations about using it until I read your great PowerPoint presentation on scripting it. Then I was sold....
            Last edited by RobertC; August 1, 2019, 03:21 PM.

            Comment


            • #36
              Jim,
              I don't know where you downloaded the files from but I would use the link to Scott's page. http://www.scottklement.com/expect/
              Then follow the directions exactly as written. If you get an error you have misspelled something so take your time and double check your syntax. I am not educated enough on these commands to explain exactly what they do. Hopefully if Scott see this post he will explain. But I do know that it works if you follow the directions precisely. Let me know how you make out.

              To Install


              Download the preceding files to the /tmp directory of the IFS on your i. When I installed them, I typed the following commands:
              CALL QP2TERM
              $ cd /tmp
              $ uncompress tcl.8.4.9.tar.Z
              $ uncompress expect.5.43.tar.Z
              $ cd /
              $ tar xf /tmp/tcl.8.4.9.tar
              $ tar xf /tmp/expect.5.43.tar
              $ ln -s /qopensys/usr/bin/stty /usr/local/bin/stty
              Press F3 to exit PASE.
              Last edited by RobertC; August 1, 2019, 02:20 PM.

              Comment


              • #37
                I suspect some of the issues Jim is encountering step from a lack of familiarity with the Unix command-line environment.

                The '$' is the default (this is completely configurable) prompt thats shown when teh system is ready to enter a command. It's much like the MS-DOS environment where it'd say something like C:\ > when its ready for a command. If you run a command and there's no visible output (it just returns you to the prompt) that generally means that all is well. If there were errors, you'd see them on the screen. the message "ln: A file or directory in the path name does not exist." is pretty self explanatory, I think? If I had to guess, I'd say that you don't have a /usr/local/bin directory. I'd suggest simply creating one, then trying the command again.

                It sure would be nice if IBM would provide expect and tcl in their "yum" package thinggy. I wonder how we can go about making that happen?

                Comment


                • #38
                  Thanks for the response Scott. I'm sure Jim will appreciate the feedback. And yes, it sure would be nice if IBM provided Expect and Tcl in their Yum bundle. How can we make it happen you ask? Well I was going to say that if enough of the tech community requests it then IBM will provide it. That may have been true years ago but I'm not so sure it applies now.....
                  Last edited by RobertC; August 1, 2019, 04:32 PM.

                  Comment


                  • #39
                    Thanks for the help, I am making progress and I have the tcl and except utilities installed.

                    I am pretty much using the exact same CL program and script as shown by Robert except modified with the appropriate server, user id and password.

                    When I run my CL program, the except is not finding the script file according to the log; "couldn't read file "script.exp": no such file or directory"

                    So it appears I have a problem with the path or the file name. I have placed the script file in what I thought was the correct directory;

                    VALUE('PATH=$PATH:/QopenSys/usr/bin:/usr/lo+
                    cal/bin && expect -f script.exp')

                    Is this command defining the path correctly ? Can you explain what the command is doing ? Is there any significance to the .exp file extension ? The extension is not visible in work with object links.

                    Comment


                    • #40
                      Originally posted by JimKerr View Post
                      When I run my CL program, the except is not finding the script file according to the log; "couldn't read file "script.exp": no such file or directory" So it appears I have a problem with the path or the file name. I have placed the script file in what I thought was the correct directory;
                      What do you consider to be the "correct directory"? I'm not sure there's any right or wrong place to put it.

                      Originally posted by JimKerr View Post
                      VALUE('PATH=$PATH:/QopenSys/usr/bin:/usr/lo+
                      cal/bin && expect -f script.exp')

                      Is this command defining the path correctly ?
                      Hmm... are you confusing the PATH with the place its looking for a script? The PATH is not used to find the script.

                      Originally posted by JimKerr View Post
                      Can you explain what the command is doing ?
                      This appears to be part of a CL command. I'm guessing it is part of a CHGVAR statement where you are setting a CL variable that you later run via QShell or similar. (I'm guessing that because its probably copied from one of my examples, and that's what I typically do.)

                      The PATH is used to find the commands you run. So you are trying to run "expect" as a command, and the way its packaged, expect will be installed into the "/usr/local/bin" IFS directory. Within the Expect script you want to run the "sftp" command, which is located in the /QOpenSys/usr/bin directory -- or, at least it used to be. (This may have changed when IBM changed the way they provided OpenSSH?) When you precede a variable with a dollar sign, such as $PATH, it inserts the value of a variable at that point in the code. So when you do PATH=$PATH:/some/dir it will set the PATH variable to itself plus the string ":/some/dir" added onto the end. In your example, you are setting PATH to itself plus the two additional directories that you want to search for the commands you're using.

                      Technically, on a system where the admin has set things up properly, setting the PATH is unnecessary, because the admin will put the locations of all of the commands into your PATH already. I included setting the PATH as part of my example because a lot of people who copy my examples don't understand Unix commands and blame me when the script doesn't work. So adding to the PATH in the script saves me a bit of frustration. Sorry, I'm going off on a tangent here...

                      Anyway... after it sets the path it runs the "expect" command, and passes it -f script.exp; If you google "expect man page" you can find the manual page for expect, and it explains that -f prefaces a file to read commands from. So it's how you specify the file that contains your expect script.


                      Originally posted by JimKerr View Post
                      Is there any significance to the .exp file extension ? The extension is not visible in work with object links.
                      I think you might have put it in a different directory than the one you're viewing with WRKLNK, because there's nothing special about it, and it is indeed visible in WRKLNK. Technically the .exp has no significance, I just thought it was a nice abbreviation for "expect". You can name the script file anything you like, it doesn't matter.

                      Comment


                      • #41
                        Originally posted by Scott Klement View Post
                        WHmm... are you confusing the PATH with the place its looking for a script? The PATH is not used to find the script.

                        The PATH is used to find the commands you run. So you are trying to run "expect" as a command, and the way its packaged, expect will be installed into the "/usr/local/bin" IFS directory. Within the Expect script you want to run the "sftp" command, which is located in the /QOpenSys/usr/bin directory
                        OK, so my understanding now is that PATH is used to set the directories where the commands are located;

                        /usr/local/bin is where the "expect" command is located.

                        /QOpenSys/usr/bin is where the "sftp" command is located.


                        When QSH is executed in the CL program, QSH will run "expect". When "expect" runs, I want to it to run using the script file script.exp.;

                        VALUE('PATH=$PATH:/QopenSys/usr/bin:/usr/local/bin && expect -f script.exp') This is the CMD variable for QSH.

                        So which directory is is file script.exp supposed to be in order for the "expect" command to find it ? Or how do I explicitly tell "expect" that script.exp is located in directory /jim/edi/scripts.

                        Sorry if I seem a bit thick, maybe it's not as complicated as I think.


                        Last edited by JimKerr; August 2, 2019, 04:06 PM.

                        Comment


                        • #42
                          Code:
                          . . .  && expect -f /jim/edi/scripts/script.exp

                          Comment


                          • #43
                            OK thanks, that would appear to make sense however the log states; "couldn't read file "/jim/edi/scripts": operation not supported on socket "

                            The script file name (script.exp) is not mentioned in the error log. Where do I go from here ? Thanks in advance.

                            Comment


                            • #44
                              "operation not supported on socket" -- this error message occurs when you provide a directory name instead of a file name.

                              For some reason the "script.exp" is getting cut off. Could it be that the CL variable that you're placing this in (was it called &CMD? I don't remember) isn't large enough? For example, perhaps the variable is defined as 500 long but your data is 510 characters, so the last 10 are chopped off?

                              Comment


                              • #45
                                Thanks for your patience. I stupidly had a typo in there.

                                Comment

                                Working...
                                X