[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: TESTPUT



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


Hi Shannon,


Yeah. I saw that. So what I did was used a CL program to pass the parms.

That'll only help if you have the parameters actually defined as VARIABLES in the CL program. (And the variables must be *CHAR 256 or larger)



In addition, in the RPG code, I did this to get rid of all the garbage at the end.

That won't work. Your code makes the assumption that there will ALWAYS be a space in the variable prior to any invalid characters. That's not a safe assumption.


A much easier and better solution to the "garbage in parameters" problem is to simply define a command (*CMD) interface for the RPG program and throw away the CL program altogether.

The *CMD interface can be used to ensure that the parms are all of the correct data type and length.

To test this theory, I wrote the following *CMD object:

CMD PROMPT('Shannon''s FTP thing')

             PARM       KWD(HOST) TYPE(*CHAR) LEN(256) MIN(1) +
                          INLPMTLEN(50) PROMPT('Host to connect to')

             PARM       KWD(USERID) TYPE(*NAME) MIN(1) +
                          PROMPT('UserID on FTP host')

             PARM       KWD(PASSWORD) TYPE(*NAME) MIN(1) +
                          DSPINPUT(*NO) PROMPT('Password on FTP Host')

             PARM       KWD(CPATH) TYPE(*CHAR) LEN(256) MIN(1) +
                          INLPMTLEN(50) PROMPT('Local File Path')

             PARM       KWD(RPATH) TYPE(*CHAR) LEN(256) MIN(1) +
                          INLPMTLEN(50) PROMPT('Remote File Path')

             PARM       KWD(BINARY) TYPE(*CHAR) LEN(1) RSTD(*YES) +
                          DFT(0) VALUES(0 1) PROMPT('Use Binary Mode')

             PARM       KWD(NAMEFMT) TYPE(*INT4) RSTD(*YES) DFT(0) +
                          VALUES(0 1) PROMPT('Remote Path Name Format')

I then took your RPG source and removed all of the code you had added to try to remove the garbage (since it's not necessary with that command object) so that it looks like the following:

      *****************************************************************
      *  To Compile:
      *
      *     CRTRPGMOD  MODULE(xxx/GETFILR1) SRCFILE(xxx/FTPAPISRC)
      *
      *     CRTPGM PGM(xxx/GETFILR1) BNDSRVPGM(LIBFTP/FTPAPIR4) ACTGRP(*NEW)
      *
      *****************************************************************

.    H BNDDIR('LIBFTP/FTPAPI') DFTACTGRP(*NO)
      /COPY LIBFTP/FTPAPISRC,FTPAPI_H                   .
     D Msg             S             52A
     D sess            S             10I 0

     D Host            S            256A
     D UserID          S             10A
     D Password        S             10A
     D CurFilPath      S            256A
     D RmtFilPath      S            256A
     D BinaryMode      S               n
     D NameFmt         S             10i 0

     C     *Entry        Plist
     C                   Parm                    Host
     C                   Parm                    UserID
     C                   Parm                    Password
     C                   Parm                    CurFilPath
     C                   Parm                    RmtFilPath
     C                   Parm                    BinaryMode
     C                   Parm                    NameFMt

.     * connect to FTP server.  If an error occurs,
.     *  display an error message and exit.
     c                   eval      sess = ftp_conn(Host:UserID:Password)
 B01 c                   if        sess < 0
     c                   eval      Msg = ftp_errorMsg(0)
     c                   dsply                   Msg
     c                   eval      *inlr = *on
     c                   return
 E01 c                   endif

.     * Change to the directory you want to put to on the remote server
 B01 c*                  if        ftp_chdir(sess: '/') < 0
     c*                  eval      Msg = ftp_errorMsg(sess)
     c*                  dsply                   Msg
     c**                 callp     ftp_quit(sess)
     c*                  eval      *inlr = *on
     c*                  return
 E01 c*                  endif

      * Set transfer mode
     c                   callp     ftp_binaryMode(sess: BinaryMode)

      * Set Name Format
      *
      ** WARNING: This only sets the name format ON THE SERVER,
      **          FTPAPI only understands the IFS-style namefmt
      **          for the 'CurFilPath' parameter!
      *
     c                   callp     ftp_namFmt(sess: NameFmt)

      * Put the file on the remote server
 B01 c                   if        ftp_put( sess
     C                                    : RmtFilPath
     C                                    : CurFilPath ) < 0
     c                   eval      Msg = ftp_errorMsg(sess)
     c                   dsply                   Msg
 E01 c                   endif

     c                   callp     ftp_quit(sess)
     c                   eval      *inlr = *on
     c                   return


I compiled the above sources with the following commands:


     CRTBNDRPG PGM(xxx) SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
     CRTCMD CMD(xxx) PGM(xxx/xxx) SRCFILE(xxx/QCMDSRC)

I then tested the command, and it worked without any problems. Note that I also changed the 'HOST' variable to be 256 long. None of my servers have host names under 10 characters, so this was necessary to test it. Not sure why you'd want to limit yourself to 10 chars there...

Hope that helps...
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------