ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

sFTP and continuation character

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

  • sFTP and continuation character

    Hello good folks.

    I am using the sFTP client on the ibm I and i am not sure what server I am connecting to. Any way the issue is with the "" continuation character. I am using it in a script and tried interactively and it is not working.

    Ex:
    Code:
    CD /br/po/outbox                          
    Rename order-2016-05-19-10-35-05-931.xml \
    archive/order-2016-05-19-10-35-05-931.xml
    I get the following error; "Couldn't rename file "/br/po/outbox/order-2016-05-19-10-35-05-931.xml" to "/br/po/outbox/": Failure".

    I am curious if there is some setting on the client side when starting sFTP to say what is the continuation character. I know in FTP is the + sign.

    Thanks, DMW.
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

  • #2
    I assume you are referring to the sftp tool that comes with OpenSSH. If not, please say so ;-)

    Next question is whether you are using Expect to control sftp, or using sftp's built-in -b batchfile option?

    Final question (I promise!) since the commands are not kept in a stream file rather than a fixed-length, record-based file, is there really a need to continue on the next line? After all, the lines can be as long as you like...

    Comment


    • #3
      I am using strqsh.
      i am using the -b
      I am trying to utilize the existing database behind our ftp application and it is only so long, not long enough, hence trying to use the continuation character.

      Thanks.
      Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

      Comment


      • #4
        Okay... I'm pretty sure there is no continuation charaqter for a -b batchfile. That leaves 3 possibilities:

        1) Make a shell script with a "here doc"
        2) Use Expect
        3) increase the record length of your existing database ftp application

        Probably #1 is the easiest, what you do is generate your stream file so that it looks as follows: (Note: Line endings should be *LF, and not *CRLF!)
        Code:
        sftp -b - $@ <<End-of-script
        cd /br/po/outbox
        Rename order-2016-05-19-10-35-05-931.xml \
        archive/order-2016-05-19-10-35-05-931.xmlEnd-of-script
        The idea is that "-b -" will get the script from "standard input", which is supplied by the "here doc". The here doc starts with <<End-of-script and contains all of the data up until End-of-script. Everything in between those delimiters is fed to standard input. Basically, you're running a QShell script that builds a virtual file in memory. We're doing that because QShell scripts have continuation characters (where sftp batchfile does not.)

        The $@ on the sftp line means "insert all parameters passed to this script here".

        You run it from Qshell directly (not via sftp -- it takes care of starting sftp) like this (where /path/to/renameScript.sh is where you put the above script in the IFS)
        Code:
        QSH CMD('/path/to/renameScript.sh user@someserver.com')
        (You can add other sftp options before user@someserver.com if you want/need...)

        Comment


        • #5
          Hmm... the forum seemed to screw up my "here doc", and I can't see an option to go back and fix it. Let me try again using the advanced editor...

          Code:
          sftp -b - $@ <<End-of-script
          cd profound
          -rm funkyname.txt
          put authurl.txt \
          funkyname.txt
          End-of-script

          Comment


          • #6
            Thanks, I am trying to convince them to let me make a new detail sFTP table that is very long.
            Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

            Comment


            • #7
              That's frustrating. If you're going to redo it, just use stream files and then you never have to worry about the limit...

              Comment


              • #8
                Two years too late but in case anyone else comes across this problem. There is another way to rename a file using rnfr and rnto.
                In the case you have a source file that is only 80 characters, this method will allow you to have a file name of up to 69 chars.

                QUOTE rnfr <from-file-name>
                QUOTE rnto <to-file-name>

                e.g. To move a file to an archive folder:

                QUOTE rnfr a_really_long_file_name......dat
                QUOTE rnto archive/a_really_long_file_name......dat
                close
                quit


                Comment


                • #9
                  GlennGG... you are confusing FTP with SFTP.

                  Comment


                  • #10
                    • Sftp using expect (user id/password authentication)

                      Hello everyone,
                      I am trying to SFTP from an iSeries to get files from a remote server with userid/password authentication. I downloaded the binaries for the Expect tool and followed the guidelines on how to write the CL program and script but I am having some issues with the script. he main problem is that I am missing the Spawn command. Is there a location I can download the spawn command from that will run in Qshell on the iSeries? I simply want to SFTP to a remote server, go to a directory, get a file and exit. I downloaded the Expect and TCL binaries from the link to Scott Klement's site: https://www.scottklement.com/expect/. I basically tailored my script around the scripts I saw on this forum, mainly the one by LBurkett99. But this won't work without the Spawn command and it not found in my IFS on the iSeries.

                    #!/usr/local/bin/expect -f
                    sftp -oPort=10022 accountname@servername
                    expect {
                    default {exit 10}
                    "password:"
                    }
                    send "******"
                    expect {
                    default {exit 20}
                    "sftp> "
                    }
                    lcd /local
                    send "cd /out\n"
                    expect {
                    default {exit 30}
                    "sftp> "
                    }
                    send "mget purchase*\n
                    sleep 60
                    expect {
                    default {exit 40}
                    "sftp> "
                    }
                    send "quit\n"
                    exit 0


                    Comment


                    • #11
                      what are you referring to when you say the "spawn command"? I've never heard of this nor needed it.

                      Comment


                      • #12
                        Do you mean the "spawn sftp" line in an Expect script? In that case, you are ussing the built-in spawn feature of Expect, it is part of expect scripts, not a separate command on the system.

                        If you're getting an error about that, it probably means that you aren't running the expect script properly.

                        Make sure you're running it via the "expect" command, like this:

                        Code:
                        expect -f /path/to/your-script
                        Or if you want to run it directly from the shell, change the "shebang" (the line that starts with #!) to this:
                        Code:
                        #!/usr/local/bin/env expect
                        That tells the shell to run it via Expect so you can run the script directly without prefacing it with the expect command.

                        Comment


                        • #13
                          Scott,
                          My apologies. I should have provided the exact command line as written. It should have been: spawn ftp accountname@servername. Because my error log indicated ''spawn command was not found'' I thought it was a separate command. Thank you for clarifying that it is a built in feature. I changed the ''shebang'' line of my script as you indicated. I changed the CL program as well. Now I am getting invalid command line while executing on Line 1. It doesn't seem to recognize the Expect command. I have tried it both ways: #!/usr/local/bin/env expect and #!/usr/local/bin/expect -f .

                          Comment


                          • #14
                            Scott,
                            I am using the EDTF command to create/modify my shell scripts on the iSeries. Does this command handle new line and end of line properly? If not, is there a way for me to use a special character or a keyboard function (such as Field Exit) to tell it when a command line ends? I am wondering if this is why I am getting invalid command error messages on Line 1.

                            Comment


                            • #15
                              I'm not sure why you're getting that. Can you tell me how to reproduce the problem?

                              Can you tell me how you're running the expect script? Exact command line used, please.

                              With regards to the end-of-line, you can control that in the EDTF command by going into the options. I'm not at work right now, so can't easily look up the syntax, but it's one of the function keys listed at the bottom of the screen, and there's a little menu where you can type an option number and a new end-of-line setting.

                              Comment

                              Working...
                              X