Strovent SystemsSign in
Reference

SFTP and scp to z/OS: EBCDIC text conversion and data sets

z/OS SFTP copies bytes as they are, so text arrives in ASCII and looks garbled. Legacy scp converts. Convert with iconv or chtag; data sets need cp.

z/OS stores text in EBCDIC. Your computer, phone or Linux server stores it in ASCII or UTF-8. IBM's OpenSSH on z/OS handles that difference differently for SFTP and for scp:

  • SFTP is binary. The bytes are copied as they are, with no conversion. A text file uploaded to z/OS stays ASCII, so z/OS tools that expect EBCDIC show it as garbage. An EBCDIC file downloaded to a PC looks like garbage there.
  • scp is text. IBM's z/OS scp assumes every file is text and converts between EBCDIC and ASCII (ISO 8859-1). Text is readable on both sides, but a binary file (zip, image, load module) is damaged.

Which one you are really using

OpenSSH 9.0 and later run scp over the SFTP protocol by default. When such a client copies to z/OS, the z/OS side is handling an SFTP transfer, so expect SFTP behaviour (no conversion). To get the old scp protocol, and the z/OS text conversion that goes with it, add -O:

scp -O notes.txt [email protected]:/u/user1/notes.txt

SFTP apps and file browsers on phones and tablets use SFTP, so they never convert.

Upload text with SFTP, then convert on z/OS

Pick one of these in a z/OS UNIX shell (SSH or OMVS) after the upload.

Convert the file to EBCDIC with iconv. IBM-1047 is the usual code page for z/OS UNIX text; use the one your site uses:

iconv -f ISO8859-1 -t IBM-1047 notes.txt > notes.ebc

Or tag the file as ASCII text and let z/OS convert it when programs read it:

chtag -tc ISO8859-1 notes.txt
ls -T notes.txt

A tag alone does not convert anything. Automatic conversion must be on, either system-wide (the AUTOCVT setting in BPXPRMxx) or for your shell with export _BPXK_AUTOCVT=ON. With ON, conversion works between IBM-1047 and ISO8859-1 only. Files with no tag are treated as EBCDIC.

The z/OS sftp client: ascii and binary

When the z/OS side runs the client, IBM's sftp has two extra subcommands that other OpenSSH builds do not have:

  • ascii converts outgoing files from the EBCDIC code page of your locale to ASCII, and incoming files back. IBM says it is only for transfers between z/OS and other UNIX systems.
  • binary turns conversion off again. Binary is the default.

They change the z/OS client only. A PC or phone client connecting to z/OS has no such command.

MVS data sets

IBM's sftp has no built-in support for MVS data sets. Paths are z/OS UNIX files. Two ways round it.

Copy with cp. Upload to a z/OS UNIX folder, convert as above, then copy into the data set. -T treats the file as text: each line becomes one record, using IBM-1047 line ends.

cp -T notes.ebc "//'USER1.NOTES.TEXT'"
cp -T notes.ebc "//'USER1.SOURCE.CNTL(NOTES)'"

Use DSFS. On z/OS releases with the Data Set File System (DSFS), data sets also appear as files in a DSFS mount (IBM's example uses /dsfs), which sftp can reach.

A line longer than the data set's record length makes cp fail. For binary data use cp -B. To download a member, reverse the steps: cp "//'USER1.SOURCE.CNTL(NOTES)'" notes.ebc, then iconv -f IBM-1047 -t ISO8859-1 notes.ebc > notes.txt, then download notes.txt.

If the site runs the z/OS FTP server, FTP can write data sets directly and converts text in ASCII mode. See EZA2537E and 451: z/OS FTP records longer than the LRECL.

From a 3270 session, IND$FILE does the EBCDIC conversion and the records in one step. See its options for record formats.

Quick checks

  • Text looks like random symbols on z/OS after an SFTP upload: the file is still ASCII. Convert it or tag it.
  • A zip or image is broken after scp to or from z/OS: the old scp protocol converted it as text. Use SFTP.
  • Accented letters or brackets come out wrong: the conversion used the wrong EBCDIC code page. See 3270 code pages.

Sources

Spotted a mistake? Email [email protected].