IBM Support

Copying a MVS text file to a Windows system using OpenSSH sftp

Troubleshooting


Problem

How do we convert a MVS text file to a Windows platform if we use sftp.

Environment

z/OS sftp windows

Resolving The Problem

OpenSSH sftp supports the IBM-1047 to ASCII conversion. However, contrary to FTP that has a feature to transform native New line encoding to the Windows <CR><LF> sequence, sftp does not convert the EOL encoding on your behalf. This needs to be done manually.

The USS EOL character is x'15' <NL>. When you convert the USS text data to ASCII, the <NL> gets converted to x'0A' <LF>. The resulting ASCII text file is valid for any UNIX system using the ASCII character set, It is not valid for Windows since the <CR><LF> sequence (x'0D0A') is used for End Of Line (EOL).

To convert an ASCII UNIX file using <LF> to the windows <CR><LF> sequence, the following shell script may be used:

$ cat convert_ascii_LF_to_CRLF
#
# converts ASCII UNIX file with unix LF x'0A' to
# windows line end CRLF or x'0D0A'
#
# calling method:
#
# convert_ascii_LF_to_CRLF <input ascii unix file name>
#
# Output file: output is created with the name of the input
# filename suffixed with a ".win"
#
set -x
cat $1 | tr '\012' '\n' | sed $(echo 's/$/\r/') | tr '\n' '\12' > $1.win

Now, if you want to move a MVS text file to an ASCII text file ready to be transfered to a Windows based machine, the following JOB step may be used:


//CONVERT EXEC PGM=BPXBATCH
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*
//STDPARM DD *
SH set-x;
cp -T "//'MVS.TEXT.FILE" /tmp/mvs.text.file ;
iconv -f IBM-1047 -t ISO8859-1 /tmp/mvs.text.file > /tmp/mvs.text.file.ascii ;
convert_ascii_LF_to_CRLF /tmp/mvs.text.file.ascii;
rm /tmp/mvs.text.file;
rm /tmp/mvs.text.file.ascii
/*

The first cp -T command copies and translates from code page IBM-037 z/OS) to IBM-1047 (IBM USS)

The iconv converts from IBM-1047 to ascii

The convert_ascii_LF_to_CRLF is the script provided above, to convert the UNIX LF to CRLF and the resulting file is name /tmp/mvs.text.file.ascii.win

You need to use sftp binary to move the .win file to the windows environment.

[{"Line of Business":{"code":"LOB56","label":"Z HW"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG90","label":"z\/OS"},"ARM Category":[{"code":"a8m0z0000000ALuAAM","label":"z\/OS->OpenSSH"}],"ARM Case Number":"","Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"All Version(s)"}]

Document Information

Modified date:
03 September 2021

UID

isg3T1024081