ftp transfer

pts.
Tags:
FTP
FTP Script
Hi I have a txt file which needs to be sent using FTP.The FTP acript will be in a seperate file.The put command in the FTP script should be updated with the latest txt file on a daily basis sio that the latest file is sent.How do i do that?Also how to i check for FTP failures and send notifications?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

Here’s a bit of code that you could use that runs FTP from a command line – it uses REXX to interpret the commands necessary for FTP :-

<b>COMMAND SOURCE</b> – Put this in QCMDSRC in Your_Library

<pre>
/* uses REXX procedure QIKFTP */

/* +
Create using the following command +
+
+
CRTCMD CMD(Your_Library/QIKFTP) +
PGM(*REXX) +
SRCFILE(Your_Library/QCMDSRC) +
SRCMBR(QIKFTP) +
REPLACE(*YES) +
*/

CMD PROMPT(‘FTP a file’)

PARM KWD(LCLFILE) TYPE(QUAL1) MIN(1) +
PROMPT(‘Local file’)

PARM KWD(RMTDIR) TYPE(*CHAR) LEN(255) MIN(1) +
PROMPT(‘Remote directory/library’)
PARM KWD(RMTFILE) TYPE(*CHAR) LEN(255) MIN(1) +
PROMPT(‘Remote filename’)

PARM KWD(OPCODE) TYPE(*CHAR) LEN(6) RSTD(*YES) +
DFT(PUT) VALUES(PUT GET DEL MPUT MGET +
APPEND) PROMPT(‘Operation code’)
PARM KWD(TFRMODE) TYPE(*CHAR) LEN(6) RSTD(*YES) +
VALUES(BINARY ASCII +
EBCDIC) PROMPT(‘Transfer mode’)

PARM KWD(SYSTEM) TYPE(*CHAR) LEN(15) MIN(1) +
PROMPT(‘System name or IP address’)

PARM KWD(USERID) TYPE(*CHAR) LEN(10) MIN(1) +
PROMPT(‘Remote system userid’)
PARM KWD(PASSWORD) TYPE(*CHAR) LEN(10) MIN(1) +
DSPINPUT(*PROMPT) PROMPT(‘Remote system +
password’)

PARM KWD(OUTPUT) TYPE(*CHAR) LEN(8) RSTD(*YES) +
DFT(*) VALUES(* *PRINT *OUTFILE) +
PROMPT(‘Output’)
PARM KWD(OUTFILE) TYPE(QUAL3) PROMPT(‘Output file’)

PARM KWD(OUTOPT) TYPE(*CHAR) LEN(8) RSTD(*YES) +
DFT(*REPLACE) VALUES(*ADD *REPLACE) +
PROMPT(‘Output option’)

QUAL1: QUAL TYPE(*NAME) LEN(10) MIN(1)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*CURLIB) (*LIBL)) PROMPT(‘Library’)
QUAL3: QUAL TYPE(*NAME) LEN(10)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*CURLIB) (*LIBL)) PROMPT(‘Library’)

</pre>

<b>REXX Source</b> – Put this in QREXSRC in Your_Library

<pre>
/* Get input variables from external command */
/* Local file library & Local file name */
PARSE UPPER ARG ‘LCLFILE(‘ Locallib ‘/’ Localfile ‘)’

/* Remote file directory & Remote file name */
PARSE UPPER ARG ‘RMTDIR(‘ Remotedir ‘)’
PARSE UPPER ARG ‘RMTFILE(‘ Remotefile ‘)’

/* Operation code (PUT, GET, etc.) */
PARSE UPPER ARG ‘OPCODE(‘ Opcode ‘)’
/* Transfer mode (ASCII, BINARY, etc.) */
PARSE UPPER ARG ‘TFRMODE(‘ Tfrmode ‘)’

/* Remote system name or IP Address */
PARSE UPPER ARG ‘SYSTEM(‘ Remotesystem ‘)’

/* Remote system user id */
PARSE UPPER ARG ‘USERID(‘ Userid ‘)’
/* Remote system password */
PARSE UPPER ARG ‘PASSWORD(‘ Password ‘)’

/* Output (Display, Print, File) */
PARSE UPPER ARG ‘OUTPUT(‘ Output ‘)’
/* Output File */
PARSE UPPER ARG ‘OUTFILE(‘ Outlib ‘/’ Outfile ‘)’

/* Output Option (*ADD, REPLACE) */
PARSE UPPER ARG ‘OUTOPT(‘ Outopt ‘)’

/******************************************************************************/
/* Check local file exists (if sending file) */

IF Opcode == ‘PUT’ | Opcode == ‘APPEND’ | Opcode == ‘MPUT’ THEN DO
‘CHKOBJ OBJ(‘Locallib’/’Localfile’) OBJTYPE(*FILE) MBR(‘Localfile’)’
if pos(‘CPF98′,rc) ¬= 0 then do
message = ‘Localfile (‘Locallib’/’Localfile’) not found’
‘SNDUSRMSG MSG(&message)’
exit(rc)
end
end

/******************************************************************************/
/* Create and build FTP script in QTEMP */

‘DLTF FILE(QTEMP/FTPCTLSCR)’
‘CRTPF FILE(QTEMP/FTPCTLSCR) RCDLEN(80)’

‘OVRDBF FILE(STDOUT) TOFILE(QTEMP/FTPCTLSCR)’

SAY Userid Password
SAY ‘LCD ‘ Locallib
SAY ‘CD ‘ Remotedir
IF Tfrmode ¬= ‘*N’
THEN SAY Tfrmode

IF Opcode == ‘PUT’ | Opcode == ‘APPEND’ | Opcode == ‘MPUT’
THEN SAY Opcode ‘ ‘ Localfile ‘ ‘ Remotefile
IF Opcode == ‘GET’ | Opcode == ‘MGET’
THEN SAY Opcode ‘ ‘ Remotefile ‘ ‘ Localfile
IF Opcode == ‘DEL’
THEN SAY Opcode ‘ ‘ Remotefile

SAY ‘QUIT’

‘DLTOVR FILE(STDOUT)’

/******************************************************************************/
/* Setup output file if necessary */

IF Output == ‘*PRINT’ THEN DO
Outlib = ‘QTEMP’
Outfile = ‘QFTPLOG’
END

IF Output ¬= ‘*’ THEN DO
‘CRTSRCPF FILE(‘Outlib’/’Outfile’) RCDLEN(92)’
IF Outopt ¬= ‘*ADD’ THEN DO
‘CLRPFM FILE(‘Outlib’/’Outfile’) MBR(‘Outfile’)’
END
‘ADDPFM FILE(‘Outlib’/’Outfile’) MBR(‘Outfile’)’
END

/******************************************************************************/
/* Execute the FTP script */

‘OVRDBF FILE(INPUT) TOFILE(QTEMP/FTPCTLSCR)’
‘OVRDBF FILE(OUTPUT) TOFILE(‘Outlib’/’Outfile’) MBR(‘Outfile’)’
‘FTP RMTSYS(‘ Remotesystem ‘)’
‘DLTOVR FILE(INPUT)’
‘DLTOVR FILE(OUTPUT)’

/******************************************************************************/
/* Reorganize the FTP output log file and print it if necessary */

IF Output ¬= ‘*’ THEN
‘RGZPFM FILE(‘Outlib’/’Outfile’) MBR(‘Outfile’) SRCOPT(*SEQNBR)’

IF Output == ‘*PRINT’ THEN
‘RUNQRY QRYFILE((‘Outlib’/’Outfile’ ‘Outfile’)) OUTTYPE(*PRINTER)’

/******************************************************************************/
/* Clean up workfiles and resources */

‘DLTF FILE(QTEMP/FTPCTLSCR)’
‘DLTF FILE(QTEMP/QFTPLOG)’

‘RCLRSC’

/******************************************************************************/
/* End of Procedure */
</pre>

Once you’ve put the source in the source files, create the command with the CRTCMD command shown in the command source.

From the command line you can prompt the command QIKFTP to run interactive or you can use it from a CL program or REXX procedure.

Instead of updating scripts, you can just change a parameter on the command for the new file name.

I’m sure other people have other ways of doing this, but it works for me.

Hope it helps,

Martin Gilbert.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following