FTPServiceの例

LANSA Integrator

FTPServiceの例


このプログラム例では以下のステップを実行します。

1.   FTPServiceのロードに必要な一連の呼び出しを行います。

2.   指定の証明情報を使用し、指定のリモートFTPサーバーに接続してログオンします(ソース・コードを修正する必要があります)。

3.   リモートFTPサーバーから現在のディレクトリの名前を取得して、この名前をジョブログに書き込みます。

4.   リモート・サーバー上の現在のディレクトリをLIFTPINディレクトリに変更します。

5.   付属のorder.xmlファイルをリモート・サーバーに送信し、このファイルをLIFTPINディレクトリに配置します。

6.   ftpセッションを終了し、サービスをアンロードしてJSMサーバーとの接続を閉じます。

注:

·         この例をテストするには、リモート・サーバー上のIFSに/LIFTPINフォルダーを作成する必要があります。

·         例をコンパイルして実行する前に、リモート・サーバー名、ユーザーID、パスワードの各自の値を指定する必要があります。これらはすべてソース・コードの開始付近にある定数に含まれています。

·         希望する場合は、例で使用されるディレクトリ名とファイル名を変更できます。

詳細については、例のコメントとコードを参照してください。

1.   ILE RPGプログラム例を作成して実行する

以下のソースをコピーしてソース・ファイル・メンバーに貼り付けます。次に、ソース・コードで上記のサーバー、ユーザーID、パスワードの定数の値を修正します。

プログラムを作成するには、CRTRPGMODコマンドとCRTPGMコマンドを使用する必要があります。必ずソース・メンバーに指定したパラメータ値を使用します。

*************************************************                   

* FTP:     example in RPG ILE of using the LANSA Integrator         

*          FTPService                                               

*                                                                   

* Note:    This is an example program containing only               

*          rudimentary exception handling                           

*                                                                   

* To create this program you must execute the following commands,   

* supplying the indicated parameter values and any others that are  

* necessary in your installation:                                   

*                                                                   

*   CRTRPGMOD MODULE(<modlib>/FTP)                                  

*             SRCFILE(<srclib>/<srcfil>)                            

*                                                                   

*   CRTPGM    PGM(<pgmlib>/FTP)                                     

*             MODULE(<modlib>/FTP)                                  

*             BNDSRVPGM(<jsmpgmlib>/DCXS882X)                       

*             ACTGRP(*CALLER)                                       

*************************************************                   

                                                       

* You MUST replace the value of these constants        

* before compiling and running this example            

                                                       

d ftpserver       c                   '<your server>'   

d ftpuser         c                   '<user id>'       

d ftppassword     c                   '<password>'      

                                                    

* IFS file and folder names used by this program    

* - to try this program you need to create the      

*   folder /LIFTPIN in your IFS                     

* - this example assumes the shipped ORDER.XML file 

*   is present in the JSM instance folder           

                                                    

d flrtarget       c                   '/LIFTPIN'     

d ftpsource       c                   'ORDER.XML'    

d ftptarget       c                   'ORDER.XML'    

                                                                      

* Declare variables for the JSM calls                                

                                                                      

d jsmsrv          s             50a   inz(*blanks)                    

d jsmsts          s             20a   inz(*blanks)                    

d jsmmsg          s            255a   inz(*blanks)                    

d jsmcmd          s            255a   inz(*blanks)                    

d bytelength      s             10i 0 inz(*zero)                      

                                                                      

* Completion messages                                                

                                                                      

d CompMsg01       c                   'JSMOPEN call completed.'       

d CompMsg02       c                   '  SERVICE_LOAD call completed.'

d CompMsg10       c                   '  CONNECT call completed.'     

d CompMsg20       c                   '  LOGIN call completed.'       

d CompMsg30       c                   '  GETDIR call completed.'      

d CompMsg31       c                   '  - current directory on +     

d                                          remote server is: '        

d CompMsg40       c                   '  CHGDIR call completed.'      

d CompMsg50       c                   '  BINARY call completed.'      

d CompMsg60       c                   '  PUT call completed.'            

d CompMsg70       c                   '  QUIT call completed.'           

d CompMsg98       c                   '  SERVICE_UNLOAD call completed.' 

d CompMsg99       c                   'JSMCLOSE call completed.'         

                                                                         

* Procedure prototypes                                                  

                                                                         

d CheckResult     pr                                                     

d  crjsts                             const like(jsmsts)                 

d  crjmsg                             const like(jsmmsg)                 

                                                                         

d SendMessage     pr                                                     

d  smText                      512a   VALUE                              

d  smType                       10a   VALUE                              

                                                                         

* Prototypes for the JSM calls                                          

                                                                         

/COPY QRPGLESRC,JSM_PROC.H                                              

                                                                         

* Open a connection to the default JSM server                           

* - because the server parameter is blank, details of the default  

*   JSM server are obtained from the data area JSMCLTDTA on IBM i

*   or from the file jsmcltdta.txt on other supported platforms)   

                                                                    

c                   callp     p_jsmopen(jsmsrv:jsmsts:jsmmsg)       

c                   callp     CheckResult(jsmsts:jsmmsg)            

c                   callp     SendMessage(CompMsg01:'*COMP')        

                                                                    

* Load the FTPService                                              

* - this example explicitly turns tracing on, overriding the       

*   settings in the manager.properties file                        

                                                                    

c                   eval      jsmcmd = 'SERVICE_LOAD'               

c                             + ' SERVICE(FTPSERVICE) TRACE(*YES)'  

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)        

c                   callp     CheckResult(jsmsts:jsmmsg)            

c                   callp     SendMessage(CompMsg02:'*COMP')        

                                                                    

* Connect to FTP server                                            

                                                                    

c                   eval      jsmcmd = 'CONNECT'                       

c                             + ' HOST(' + %trim(ftpserver) + ')'      

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)           

c                   callp     CheckResult(jsmsts:jsmmsg)               

c                   callp     SendMessage(CompMsg10:'*COMP')           

                                                                       

* Login to FTP server                                                 

                                                                       

c                   eval      jsmcmd = 'LOGIN'                         

c                             + ' USER(' + %trim(ftpuser) + ')'        

c                             + ' PASSWORD(' + %trim(ftppassword) + ')'

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)           

c                   callp     CheckResult(jsmsts:jsmmsg)               

c                   callp     SendMessage(CompMsg20:'*COMP')           

                                                                       

* Get the current directory on the remote server                      

* - the current directory is returned in the jsmmsg field             

                                                                       

c                   eval      jsmcmd = 'GETDIR'                        

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)           

c                   callp     CheckResult(jsmsts:jsmmsg)            

c                   callp     SendMessage(CompMsg30:'*COMP')        

                                                                    

* ... output the current directory name into the joblog ...        

                                                                    

c                   callp     SendMessage(CompMsg31 + %trim(jsmmsg) 

c                                         :'*COMP')                 

                                                                    

* Change the current directory on the remote server                

                                                                    

c                   eval      jsmcmd = 'CHGDIR'                     

c                             + ' PATH(' + %trim(flrtarget) + ')'   

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)        

c                   callp     CheckResult(jsmsts:jsmmsg)            

c                   callp     SendMessage(CompMsg40:'*COMP')        

                                                                    

* Set binary mode                                                  

                                                                    

c                   eval      jsmcmd = 'BINARY'                     

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)        

c                   callp     CheckResult(jsmsts:jsmmsg)         

c                   callp     SendMessage(CompMsg50:'*COMP')     

                                                                 

* Put file onto remote server                                   

                                                                 

c                   eval      jsmcmd = 'PUT'                     

c                             + ' FROM(' + %trim(ftpsource) + ')'

c                             + '   TO(' + %trim(ftptarget) + ')'

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)     

c                   callp     CheckResult(jsmsts:jsmmsg)         

c                   callp     SendMessage(CompMsg60:'*COMP')     

                                                                 

* Quit the FTP session                                          

                                                                 

c                   eval      jsmcmd = 'QUIT'                    

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)     

c                   callp     CheckResult(jsmsts:jsmmsg)         

c                   callp     SendMessage(CompMsg70:'*COMP')     

                                                                 

* Unload the FTPService                                         

                                                               

c                   eval      jsmcmd = 'SERVICE_UNLOAD'        

c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)   

c                   callp     CheckResult(jsmsts:jsmmsg)       

c                   callp     SendMessage(CompMsg98:'*COMP')   

                                                               

* Close the connection to the JSM server and finish           

                                                               

c                   callp     p_jsmclose(jsmsts:jsmmsg)        

c                   callp     CheckResult(jsmsts:jsmmsg)       

c                   callp     SendMessage(CompMsg99:'*COMP')   

c                   eval      *inlr = *on                      

c                   return                                     

                                                               

*************************************************             

* Procedure to check the result of a Java Service Manager call

*************************************************             

p CheckResult     b                                            

d CheckResult     pi                                           

d  crjsts                             const like(jsmsts)       

d  crjmsg                             const like(jsmmsg)            

d  crText         s            512a                                 

d  crMsg1         c                   const('JSM Status : ')        

d  crMsg2         c                   const('JSM Message: ')        

d  crMsg3         c                   const('JSM Service error has +

d                                            occurred')             

c                   if        crjsts <> 'OK'                        

c                   eval      crText = crMsg1 + crjsts              

c                   callp     SendMessage(crText:'*DIAG')           

c                   eval      crText = crMsg2 + crjmsg              

c                   callp     SendMessage(crText:'*DIAG')           

c                   callp     SendMessage(crMsg3:'*ESCAPE')         

c                   endif                                           

p CheckResult     e                                                 

                                                                    

*************************************************                  

* Procedure to send a program message                              

*************************************************                  

p SendMessage     b                                                 

                                                                    

d SendMessage     pi                                             

d smText                       512a   VALUE                      

d smMsgT                        10a   VALUE                      

                                                                 

d smMsgI          s              7a   inz('CPF9897')             

d smMsgF          s             20a   inz('QCPFMSG   *LIBL     ')

d smDtaL          s             10i 0 inz(%size(smText))         

d smStkE          s             10a   inz('*')                   

d smStkC          s             10i 0 inz(1)                     

d smMsgK          s              4a                              

d smErrC          s             10i 0 inz(0)                     

                                                                 

c                   if        smMsgT = '*ESCAPE'                 

c                   eval      smMsgI = 'CPF9898'                 

c                   endif                                        

                                                                 

c                   call      'QMHSNDPM'                         

c                   parm                    smMsgI               

c                   parm                    smMsgF               

c                   parm                    smText               

c                   parm                    smDtaL

c                   parm                    smMsgT

c                   parm                    smStkE

c                   parm                    smStkC

c                   parm                    smMsgK

c                   parm                    smErrC

                                                  

p                 e