FTPServiceの例

LANSA Integrator

FTPServiceの例


このフォームは、指定のリモートFTPサーバーに接続します。FTP接続を確立すると、GETコマンドでリモート・サーバーからファイルを取得したり、PUTコマンドでローカル・サーバーからリモート・サーバーにファイルをコピーしたりすることができます。リモート・サーバー上の現在のディレクトリを必要に応じて変更できます。

使用するサイトに合うように、表示される省略値を修正します。

 

* Uses Integrator Services:FTPService

* 1. Allows connection to a remote FTP server

* 2. Change the current directory on the remote server

* 3. GET a file from or PUT a file onto the remote server

* The following fields must be defined in your data dictionary to support this function:

* filname alpha 10

* filnbr alpha 6

* jobname alpha 10

* jobuser alpha 10

* jobnbr alpha 6

* status alpha 10

* jsmserver alpha 20

* jsmpsswrd alpha 10

* jsmuserid alpha 10

* jsmsts alpha 20

* jsmmsg alpha 255

* jsmpath alpha 150

* jsmfrom alpha 150

* jsmto alpha 150

* jsmhdle char 500

* jsmcmd alpha 4

* Beginning of RDML commands **********

function options(*DIRECT)

begin_com role(*EXTENDS #PRIM_FORM) clientheight(260) clientwidth(615) framestyle(Dialog) height(294) left(459) top(150) width(623)

define_com class(#PRIM_GPBX) name(#GPBX_1) caption('Connect to FTP server') displayposition(1) height(45) left(5) parent(#COM_OWNER) tabposition(1) tabstop(False) top(5) width(600)

define_com class(#PRIM_GPBX) name(#GPBX_2) caption('FTP details ') displayposition(2) height(117) left(5) parent(#COM_OWNER) tabposition(2) tabstop(False) top(60) width(600)

define_com class(#jsmserver.Visual) name(#jsmserver) displayposition(1) left(8) marginleft(50) parent(#GPBX_1) tabposition(1) top(16) width(209)

define_com class(#jsmuserid.Visual) name(#jsmuserid) displayposition(2) left(224) marginleft(50) parent(#GPBX_1) tabposition(2) top(16) width(150)

define_com class(#jsmpsswrd.Visual) name(#jsmpsswrd) displayposition(3) left(400) marginleft(50) parent(#GPBX_1) tabposition(3) top(16) width(150)

define_com class(#jsmpath.Visual) name(#jsmpath) caption('Current Directory') displayposition(1) height(19) labeltype(Caption) left(9) marginleft(100) parent(#GPBX_2) tabposition(1) top(18) usepicklist(False) width(555)

define_com class(#jsmfrom.Visual) name(#jsmfrom) displayposition(2) left(9) marginleft(100) parent(#GPBX_2) tabposition(2) top(47)

define_com class(#jsmto.Visual) name(#jsmto) displayposition(3) left(9) marginleft(100) parent(#GPBX_2) tabposition(3) top(76)

define_com class(#PRIM_PHBN) name(#Connect) caption('Connect') displayposition(1) left(5) parent(#PANL_1) tabposition(1) top(5) width(100)

define_com class(#PRIM_PHBN) name(#Get) caption('Get File') displayposition(4) enabled(False) left(335) parent(#PANL_1) tabposition(4) top(5) width(100)

define_com class(#PRIM_PHBN) name(#Put) caption('Put File') displayposition(3) enabled(False) left(225) parent(#PANL_1) tabposition(3) top(5) width(100)

define_com class(#PRIM_PHBN) name(#Disconnect) caption('Disconnect') displayposition(5) enabled(False) left(445) parent(#PANL_1) tabposition(5) top(5) width(100)

define_com class(#PRIM_PHBN) name(#SetDirectory) caption('Change Directory') displayposition(2) enabled(False) left(115) parent(#PANL_1) tabposition(2) top(5) width(100)

define_com class(#PRIM_STBR) name(#STBR_1) displayposition(4) height(24) left(0) messageposition(1) parent(#COM_OWNER) tabposition(4) tabstop(False) top(236) width(615)

define_com class(#PRIM_PANL) name(#PANL_1) displayposition(3) height(32) left(5) parent(#COM_OWNER) tabposition(3) tabstop(False) top(187) width(600)

evtroutine handling(#com_owner.Initialize)

set com(#com_owner) caption(*component_desc)

#jsmhdle := *default

* default values

* #jsmserver := '<server>'

* #jsmuserid := '<user id>'

* #jsmpsswrd := '<password>'

#jsmserver := LANSA01

#jsmuserid := KATE

#jsmpsswrd := LANSA

endroutine

mthroutine name(Connect)

if (#jsmhdle.IsNull)

* connect the JSMX client to the Java Service Manager and start a thread for the service

* Start local JSM server

use builtin(jsmx_open) to_get(#jsmsts #jsmmsg #jsmhdle)

#com_owner.check( #jsmsts #jsmmsg )

* Load the service

#jsmcmd := 'Service_Load Service(FTPService)'

use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* Connect to remote FTP server

#jsmcmd := 'Connect Host(' + #jsmserver + ')'

use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* Login

#jsmcmd := 'Login User(' + #jsmuserid + ') password(' + #jsmpsswrd + ')'

use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* get the current directory

use builtin(jsmx_command) with_args(#jsmhdle GetDir) to_get(#jsmsts #jsmmsg)

#jsmpath := #jsmmsg

endif

endroutine

mthroutine name(DisConnect)

* Quit

use builtin(jsmx_command) with_args(#jsmhdle 'Quit') to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* Unload service

use builtin(jsmx_command) with_args(#jsmhdle 'Service_Unload') to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* Close the thread

use builtin(jsmx_close) with_args(#jsmhdle) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

#jsmhdle := *null

endroutine

mthroutine name(GetFile)

* Binary mode

use builtin(jsmx_command) with_args(#jsmhdle 'Binary') to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* Get file from remote server

#jsmcmd := 'get from(' + #jsmfrom + ') to(' + #jsmto + ')'

use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

endroutine

mthroutine name(PutFile)

* Binary mode

use builtin(jsmx_command) with_args(#jsmhdle 'Binary') to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

* Put file onto remote server

#jsmcmd := 'put from(' + #jsmfrom + ') to(' + #jsmto + ')'

use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

endroutine

evtroutine handling(#Connect.Click)

#com_owner.Connect

if (#jsmsts = OK)

#Connect.enabled := false

#SetDirectory.enabled := true

#Put.enabled := true

#Get.enabled := true

#Disconnect.enabled := true

endif

endroutine

evtroutine handling(#SetDirectory.Click)

* Change the current directory

#jsmcmd := 'chgdir path(' + #jsmpath + ')'

use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)

#com_owner.check( #jsmsts #jsmmsg )

endroutine

evtroutine handling(#Get.Click)

#com_owner.GetFile

endroutine

evtroutine handling(#Put.Click)

#com_owner.PutFile

endroutine

evtroutine handling(#Disconnect.Click)

#com_owner.DisConnect

if (#jsmsts = OK)

#Connect.enabled := true

#SetDirectory.enabled := false

#Put.enabled := false

#Get.enabled := false

#Disconnect.enabled := false

endif

endroutine

* check the JSM return status

mthroutine name(check)

define_map for(*input) class(#jsmsts) name(#i_status)

define_map for(*input) class(#prim_alph) name(#i_message)

message msgtxt(#i_status + ' :' + #i_message)

endroutine

end_com