user715079
user715079

Reputation: 71

Transfer a file from AS400 to another machine in the same network

I am trying to export the data of a table on AS400 to another machine through iSeries commands but I am stacked in the middle of the process. I have a stored procedure in which I create the CSV file but after completion I need to transfer this file to another machine (which is of course connected to the AS400).

In the stored procedure, I used the CPYTOIMPF command to export table data to CSV and I wrote the file on the AS400 file system. I don't know if there is an option to write the file directly to another machine.

CALL QSYS2.QCMDEXC(
 'CPYTOIMPF FROMFILE(LIBRARY/TABLE) TOSTMF('/QIBM/UserData/TestFolder/2.CSV') STMFCODPAG(*PCASCII) RCDDLM(*CRLF)'
);

This step is completed and the file is written on that directory.

Now I need to transfer this file to a web server that is connected to AS400 without after the above command is completed.

How can I do that?

Upvotes: 0

Views: 3816

Answers (1)

jmarkmurphy
jmarkmurphy

Reputation: 11493

You can use FTP on IBM i. Here is a modified example from the IBM Knowledge Center

This is a CL program

PGM 
  OVRDBF   FILE(INPUT) TOFILE(MYLIB/QCLSRC) MBR(FTPCMDS) 
  OVRDBF   FILE(OUTPUT) TOFILE(MYLIB/QCLSRC) MBR(OUT) 
  FTP      RMTSYS(SYSxxx) 
ENDPGM 

This program overrides the input of the FTP client to a script in MYLIB/QCLSRC member FTPCMDS, and the output of the FTP client to MYLIB/QCLSRC member OUT. The first line of the script must contain the userid and password for the remote location.

Here is a sample script from the same Knowledge Center reference:

ITSO ITSO    <== This is the user id and password
CD ITSOLIB1 
SYSCMD CHGCURLIB ITSOLIB2 
GET QCLSRC.BATCHFTP QCLSRC.BATCHFTP (REPLACE 
QUIT 

This should not be used outside your network as the user id an password are sent in plain text. It also can be a security risk as production user id's and passwords must be stored in plain text in the source file.


In addition, Scott Klement has a presentation on how to use ssh, scp, and sftp on IBM i. This is quite a long thing, so you might want to read about it here.

A short summary is that scp might be the easiest way to go. but you will need to:

  1. Make sure that OpenSSH option of the OS is installed.
  2. Make sure your Windows server is set up as an ssh server.
  3. Set up a digital key to use for the transfer. Private key goes on client side, and public key goes on server side.
  4. Use scp fromfile user@host:tofile in Pase to transfer the file.

Upvotes: 0

Related Questions