ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to get remote server directory content using FTP

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

  • How to get remote server directory content using FTP

    Hi All,

    I need to get directory content into output file using FTP.
    remote system: abc.com
    remote directory: print/dir1/

    To accomplish this I used following FTP command.
    1. FTP abc.com
    2. LS /print/dir1/ > /qsh.lib/my-lib.lib/output.txt

    On my LS command above giving error but if I use this in QSHELL like following then it works.
    LS /print/dir1/ > /qsh.lib/my-lib.lib/qddssrc.file/output.mbr

    If I use QSHELL then how to connect with remote system because LS command works here.
    Cheers...
    Nil

  • #2
    Re: How to get remote server directory content using FTP

    Try the following... I was able to do this...

    ftp into the machine
    Code:
    syscmd chgcurlib yourlib
    ls * (DISK
    Now there will be a file called YOURLIB/LSOUTPUT that you can read from.

    Comment


    • #3
      Re: How to get remote server directory content using FTP

      You will of course need to cd to the directory that you are wanting to view.

      Comment


      • #4
        Re: How to get remote server directory content using FTP

        Originally posted by Nil
        2. LS /print/dir1/ > /qsh.lib/my-lib.lib/output.txt

        On my LS command above giving error...
        If that is the exact command that you used, it seems likely to give an error. You probably shouldn't be creating directories that have a .LIB extension. And if you didn't create such a directory, there should be no way to access the QSH library using that path (without some weird symbolic links).

        What exactly did you want that LS command to do? were you expecting it to list the directory into a file on the remote system?

        It's not required to do it that way. You can have a list created on your local system by overriding the FTP OUTPUT file to a source member on your system.
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment


        • #5
          Re: How to get remote server directory content using FTP

          Tom... I would assume that he meant to say /qsys.lib rather than /qsh.lib... (and output.mbr instead of output.txt) probably just a typo.

          Comment


          • #6
            Re: How to get remote server directory content using FTP

            Scott... That seemed likely, but it's a good example why cut/paste of actual code is better than manual typing when asking on a forum, as well as why it's usually a good idea to include message IDs or error codes. It's not easy to comment on stuff that isn't shown; comments might only be certain about what is seen.

            But I should've also noted "output.txt". Must've stopped parsing when the first problem was seen or simply from thinking it would be valid if the path was valid. A different LS path was shown for the success in QShell.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment


            • #7
              Re: How to get remote server directory content using FTP

              Originally posted by tomliotta View Post
              If that is the exact command that you used, it seems likely to give an error. You probably shouldn't be creating directories that have a .LIB extension. And if you didn't create such a directory, there should be no way to access the QSH library using that path (without some weird symbolic links).

              What exactly did you want that LS command to do? were you expecting it to list the directory into a file on the remote system?

              It's not required to do it that way. You can have a list created on your local system by overriding the FTP OUTPUT file to a source member on your system.
              Thank you everyone for the replies.

              Tom, I want all the file list/content of 'print/dir1' from the server abc.com into my local machine/library in the form of file, that file could be PF so that I can read into my RPGLE.

              I know that I can do this with OVRDBF (OUTPUT) but there is a parameter to DIR or LS command to save its output so how do I accomplish using QSHELL or FTP, Please also let me know how do I connect with abc.com using QSHELL interpreter because following command works but it takes the list from my local machine and not from abc.com

              LS /print/dir1/ > /qsh.lib/my-lib.lib/qddssrc.file/output.mbr
              I can use this command but I want first to connect with abc.com then get the list into local machine.
              Cheers...
              Nil

              Comment


              • #8
                Re: How to get remote server directory content using FTP

                Originally posted by danlong005 View Post
                Try the following... I was able to do this...

                ftp into the machine
                Code:
                syscmd chgcurlib yourlib
                ls * (DISK
                Now there will be a file called YOURLIB/LSOUTPUT that you can read from.
                It works, great..thank you so much...
                Cheers...
                Nil

                Comment


                • #9
                  Re: How to get remote server directory content using FTP

                  In general, you won't run a command on a remote system that is going to put its output into a file on your local system. Unless you can do some serious programming, that simply isn't going to work well at all.

                  Assuming that both systems are AS/400-series and their network connections work properly, a couple possible somewhat simple ways to get it done would be have the remote command send its output to a /QFileSvr.400 or /QNTC or NFS link back to something on your local system. Any of those could take a lot of work before seeing success, depending on how both systems are set up.

                  If you somehow need to get it done in QShell, first thing I would try would be the rexec() utility. Try it in QShell like this:
                  Code:
                  ===> rexec -p rmtPwd -u rmtUser rmtHost "QSH CMD('ls -l /print/dir1')"
                  For 'rmtPwd', put the password on the remote system. For 'rmtUser', put the remote user ID. For 'rmtHost', put the remote server host name. Note that rexec() runs in QShell on your local system, and the example also sends a QSH command to run on the remote system.

                  The remote server will need to have a rexec() server running. You can use whatever options you think are needed for the ls utility. I used the -l option to get the long format. I didn't use an option to process subdirectories. You can redirect the output from rexec() to a file on your local system.
                  Tom

                  There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                  Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                  Comment


                  • #10
                    Re: How to get remote server directory content using FTP

                    Originally posted by Nil View Post
                    It works, great..thank you so much...
                    Ah, glad danlong005's suggestion was good for you. Was beginning to think earlier suggestions weren't what you wanted.
                    Tom

                    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                    Comment

                    Working...
                    X