Co:Z SFTP with Dataset Support - User's Guide

3. Using the Co:Z sftp server

The following chapters describe how to use sftp with dataset support. The examples below assume that you have installed and configured the Co:Z toolkit on your z/OS and target systems, and have properly configured the sftp sshd subsystem.

All examples in the following sections can be run by most sftp clients, either from z/OS or from other platforms (Windows, linux, etc..). Note: There are some differences in the way clients interact with the server, so the output shown in the examples below (performed with the OpenSSH sftp client) may not match your output exactly.

3.1 Setting, displaying and clearing file transfer options

File transfer options are set with the special ls request of the form: ls /+<name=value>. They can be cleared with a request of the form: ls /+NO<name>.

Multiple options can be set by separating the key=value pairs with commas. An error is returned if one or more of the options was incorrectly specified, but the remaining options are set as requested.

The options directory /+/ is a pseudo directory on the server, and it is possible to make it the working directory via the cd /+ command. From this directory, options may be set and listed without the /+ prefix.

The active options and their settings can be displayed by issuing the command ls /+.

General transfer options

The following table describes the general transfer options. The usage columns describe when the option (if active) will apply during transfer.

Table 3.1. General transfer options

KeywordUsage
NameValueDatasetsPOSIXRead (Get)Write (Put)
clientcp<codepage>XXXX
linerulecr | crlf | crnl | lf | nl | rdw | ibmrdw | mfrdw | flexible | noneXXXX
modebinary | textXXXX
overflowerror | flow | trunc | wrapX X
pad<pad_char>X X
servercp<codepage>XXXX
trim X X

clientcp

Specifies the name of the client codepage used when performing text mode transfers. Data will be converted between the server codepage (servercp) and this code page. The codepage must either be a single byte codepage or any multi-byte codepage that has single-byte line terminators (e.g. UTF-8). The z/OS Unix command iconv -l lists the available codepages. The default, if not specified, is ISO8859-1.

linerule

The values cr, crlf, crnl, lf, nl specify that, for text mode transfers, lines will be terminated with the given characters in the client codepage. flexible may be used when writing to files or datasets to indicate that any combination of cr, lf, or newline will be recognized as a line terminator. rdw specifies that a 4 byte, big endian length will prefix each record, which ibmrdw specifies that IBM-style RDWs are used as prefixes. mfrdw indicates that Micro-focus file and records headers are used. The default is flexible for writing and lf for reading.

mode

Specifies whether transfers are as-is (binary) or subject to codepage/linerule/overflow/pad processing (text). The default is binary.

overflow

For text-mode dataset write processing, controls the treatment of lines longer than the maximum dataset record length.

pad

For text-mode dataset write processing, specifies the character to use when padding lines into fixed-length dataset records. If not specified, the default is a space character in the server codepage.

servercp

Specifies the name of the server codepage used when performing text mode transfers. Data will be converted between the client codepage (clientcp) and this code page. The default, if not specified, is default codepage for the server's process.

trim

For text-mode dataset read transfers, enabling this options will cause pad characters to be trimmed from the dataset records as they are read.

Miscellaneous options

The following table describes the miscellaneous options. These options do not apply to transfer operations, but affect the behaviour of the sftp-server.

Table 3.2. Miscellaneous options

Keyword 
NameValueNotes
loglevelE | W | N | I | D | T | F

Sets the logging level of the Co:Z sftp-server. The UPPER CASE values correspond to the list: (Error, Warning, Info, Notice, Debug, Trace, Fine).

showall 

If active, all options will be shown on option display (ls /+). Inactive options are shown with a prefix of NO.


Dataset allocation options

The following table describes options that apply when transferring MVS datasets. The z/OS BPXWDYN service is used for dataset allocation and these options correspond to keywords available with BPXWDYN with similar syntax except that:

  • keyword=value is used rather than keyword(value)

  • periods are used in place of commas

  • other minor differences as described below

The usage columns below describe when the option (if active) will apply during dataset transfer (these options never apply during POSIX file transfers). For more information on BPXWDYN, see Using REXX and z/OS UNIX System Services - SA22-7806

Table 3.3. BPXWDYN options

KeywordUsage
NameValueReadWrite NewWrite ExistingSysout
allowmount XXX
blksize<numeric> X X
bufno<numeric>XXX
copies<numeric> X
dataclas<alphanum> X
destdest[.user] X
dir<numeric> X
dispold | shr | mod | newXXX
dsorgps | po | da X
forms<alphanum> X
gdgnt  X
hold  X
labelnl | sl | nsl | sul | blp | ltm | al | aul X
like<Dataset Name> X
lrecl<numeric> X X
maxvol<numeric> X
mgmtclas<alphanum> X
norecall X X
outdes<alphanum> X
recfm<alphanum> X X
release XXX
retpd<numeric> X
sequence<numeric> X
space[blk. | trk. | cyl.]primary[.secondary] X
spin  X
storclas<alphanum> X
sysout<sysout_class> X
trtchnoncomp | comp | c | e | et | t X
ucount<numeric>XXX
unit<numeric> X
vol<alphanum> X
writer<alphanum> X

Example: Setting and displaying basic options

sftp> ls /+mode=text     1
/+mode=text
sftp> ls /+     2
/+/clientcp=ISO8859-1     /+/error.log     /+/mode=text     
/+/servercp=IBM-1047
1

The option command ls /+mode=text is used to set the transfer mode to text. mode=binary is the default.

2

The option list command ls /+ shows the options currently in effect. In this case, the codepages clientcp and servercp are set to the defaults.

Example: Setting multiple options

sftp> ls /+lrecl=80,recfm=fb,space=trk.3.2     1
/+lrecl=80,recfm=fb,space=trk.3.2
1

Multiple options can be specified, separated by commas. Note that the SPACE parameter uses periods for commas to avoid ambiguity.

Example: Showing all options

sftp> ls /+showall      1
/+showall=true  
sftp> cd /+     2
sftp> ls     3
NOallowmount            NOblksize               NObufno                 
NOcopies                NOdataclas              NOdest                  
NOdir                   NOdisp                  NOdsorg                 
NOforms                 NOgdgnt                 NOhold                  
NOlabel                 NOlike                  NOmaxvol                
NOmgmtclas              NOnorecall              NOoutdes                
NOrelease               NOretpd                 NOsequence              
NOspin                  NOstorclas              NOsysout                
NOtrim                  NOtrtch                 NOucount                
NOunit                  NOvol                   NOwriter                
clientcp=ISO8859-1      error.log               linerule=flexible       
lrecl=80                mode=text               overflow=wrap           
recfm=FB                servercp=IBM-1047       showall                 
space=TRK.3.2                                
sftp> ls noshowall,norecfm      4
noshowall,norecfm     
sftp> ls
clientcp=ISO8859-1      error.log               lrecl=80                
mode=text               servercp=IBM-1047       space=TRK.3.2
1

The option command ls /+showall is used to set the option listing mode to show all options, even those that are not active.

2

Since the options are treated as entries in a pseudo directory, the cd command can be used to make that directory the working remote directory.

3

Issuing the ls from the options directory will show all of the options. Those that are not active are prefixed with the string NO. Note that the options can be listed even if the current working directory is not the options pseudo dir with the command ls /+.

4

Active options can be de-activated by prefixing the option with the string NO. In this example, the showall option is cleared, as well as the recfm option.

3.2 Reading the error log

Most implementations of the sftp specification, including OpenSSH, do not allow for transmission of detailed information from the server to the client in the event of an error. Adding dataset transfers to the mix only increases the need for better error reporting. To help alleviate this problem, the Co:Z sftp implementation provides a comprehensive logging facility that can be enabled and tuned by each user session.

Several of the above option listing examples show error.log as one of the options. This is actually an alias for the running session's log file, which is usually written to the /tmp directory (See Chapter 2, Installation and Customization for more information on where this file is written). This alias can be used to easily retrieve the log at anytime and examine it from the client.

This feature makes it possible to examine detailed error information from the client without having to abandon the active sftp session. Users of graphical clients such as winSCP and gFTP see an even greater advantage in that the error.log file can be viewed simply by selecting the file and transferring it in view mode.

Example: Getting and displaying the error log

sftp> rm //user.coz.sampjcl     1
Removing //user.coz.sampjcl
Couldn't delete file: Failure     2
sftp> get /+/error.log     3
Fetching /+/error.log to error.log
/+/error.log                         100%   68     0.1KB/s   00:00    
sftp> !cat error.log     4
ZosUtil[E]: Dataset "USER.COZ.SAMPJCL" is a PDS. Use rmdir instead.
sftp>
1

This command attempts to delete a PDS with the rm which is not allowed.

2

The request fails, but the standard sftp error message is not very helpful.

3

To get better information, the error.log from the options directory is requested.

4

Using the local shell command cat to display the log gives detailed error information.

3.3 Working with Datasets

The Co:Z implementation of sftp accepts two prefix strings to identify MVS datasets as absolute paths. The first (//) is consistent with IBM's common usage. A secondary form (/-/) is also available, as not all sftp clients will allow double slash characters to be sent.

Navigating Datasets

The sftp cd command can be used to navigate around the z/OS dataset space. Using the dataset prefix // or /-/, the dataset space can be entered. Once there, traversal up and down various dataset levels can be performed similarly to hierarchical file systems.

Partitioned datasets are treated as directories as well. Once a PDS is made the current working directory, its members can be listed and retrieved like normal files.

Just as listing the entire catalog from the root is not allowed, it is not possible to make the catalog root the current working directory. As such, the command cd // will fail.

Example: Navigating the dataset space

sftp> cd //user     1
sftp> pwd     2
Remote working directory: //USER
sftp> cd coz.testjcl     3
sftp> pwd
Remote working directory: //USER.COZ.TESTJCL
sftp> cd ..     4
sftp> pwd
Remote working directory: //USER.COZ
1

Using the dataset prefix //, the high level qualifier user is specified. For cd commands, the dataset name is case insensitive.

2

The pwd command will list the current working dataset level. Note that the name is properly displayed in uppercase

3

Multiple levels can be traversed at a time. Instead of using the normal separator (.), a slash can be used: cd coz/testjcl.

4

The cd .. command will move up a level, as expected.

Transferring Datasets

The get and put commands are used to transfer datasets and PDS members. By default, the transfer mode is binary, and when storing new datasets, the DCB defaults are determined by the system and are often RECFM=U.

Any options previously set via the ls /+option=value are in effect for any given transfer.

Example: Get a text sequential dataset

$ sftp user@zos.com     1
Connecting to zos.com...
user@zos.com's password:
sftp> ls /+mode=text     2
/+mode=text  
sftp> get //USER.LOG.MISC     3
Fetching //USER.LOG.MISC to USER.LOG.MISC
1

This example shows the full connection process, using keyboard-interactive password authentication.

2

The default transfer mode of binary is overridden and set to text.

3

The get command uses the dataset path prefix // (or, optionally /-/) to specify that a dataset is being requested.

Example: Get PDS members

sftp> ls /+     1
/+/clientcp=ISO8859-1     /+/mode=text     /+/servercp=IBM-1047      
sftp> get //user.ssh.jcl(sshd)     2
Fetching //user.ssh.jcl(sshd) to user.ssh.jcl(sshd)
1

If this transfer is performed after the prior example, the transfer mode will still be text. Using the ls /+ command quickly confirms the active options.

2

The get command uses the dataset path prefix // and pds member name in parentheses to identify the member to get. Note again that the dataset name for transfers is case insensitive.

Example: Get a PDS member

sftp> get //user.coz.sampjcl(cozproc) cozproc.txt          1
Fetching //user.coz.sampjcl(cozproc) to cozproc.txt

sftp> cd //user.coz.sampjcl     2
sftp> get runcoz     3
Fetching //USER.COZ.SAMPJCL/runcoz to runcoz

sftp> get *     4
Fetching //USER.COZ.SAMPJCL/@@README to @@README
Fetching //USER.COZ.SAMPJCL/BPXBATCH to BPXBATCH
Fetching //USER.COZ.SAMPJCL/BPXBATSL to BPXBATSL
Fetching //USER.COZ.SAMPJCL/COZCFGD to COZCFGD
Fetching //USER.COZ.SAMPJCL/COZPROC to COZPROC
Fetching //USER.COZ.SAMPJCL/DTLSPAWN to DTLSPAWN
Fetching //USER.COZ.SAMPJCL/GPGDSN to GPGDSN
Fetching //USER.COZ.SAMPJCL/GREPDSN to GREPDSN
Fetching //USER.COZ.SAMPJCL/GREPSED to GREPSED
Fetching //USER.COZ.SAMPJCL/OFFLDSMF to OFFLDSMF
Fetching //USER.COZ.SAMPJCL/RUNCOZ to RUNCOZ
Fetching //USER.COZ.SAMPJCL/RUNCOZ2 to RUNCOZ2
Fetching //USER.COZ.SAMPJCL/RUNCOZ3 to RUNCOZ3
Fetching //USER.COZ.SAMPJCL/RUNSPAWN to RUNSPAWN
Fetching //USER.COZ.SAMPJCL/RUNSPWN2 to RUNSPWN2
Fetching //USER.COZ.SAMPJCL/TDIRK to TDIRK
Fetching //USER.COZ.SAMPJCL/WGET2DSN to WGET2DSN
1

The get can be used to get a member from a fully qualified dataset.

2

The cd command is used to make a PDS the current working "directory".

3

The get command uses just the member name to retrieve the desired member.

4

The get * command can be used to retrieve all members at once.

Example: Put a text MVS dataset, overriding DCB attributes

...
sftp> ls /+mode=text,lrecl=80,recfm=fb     1
/+mode=text,lrecl=80,recfm=fb  
sftp> put afile.txt //USER.AFILE.TXT     2
Uploading afile.txt to //USER.AFILE.TXT
1

The option command ls /+mode=text,lrecl=80,recfm=fb is used to set the transfer mode to text, and set the DCB attributes for the new dataset USER.AFILE.TXT. This overrides the system default for new datasets. Input lines will be broken on CR, LF, or CRLF and lines longer than allowed by the dataset will be wrapped onto multiple records. The options linerule and overflowrule can be used to override those settings.

2

The put command uses the specialized path prefix // (or, optionally /-/) to specify the dataset name.

Listing datasets and PDS directories

MVS datasets can be listed using the sftp ls command. Partitioned datasets are treated as directories with their members as entries.

In order to support existing sftp clients, several considerations have to be made when listing datasets:

  • The ls lists multiple dataset levels (by default), and therefore can return a large amount of information. As such, listings that would involve searching the entire catalog, such as ls // or ls //A* are not allowed. Furthermore, because of the way sftp clients interact with the server, the following style of command is not supported: ls //USER.LVL1*. However, the same effect can be produced by either using directory notation for searching the catalog (ls //USER/LVL1*) or changing to the desired level and issuing a relative listing command:

    cd //USER
    ls LVL1*
  • Where possible, dataset names are treated as case insensitive. A get or put can specify the name in either lower or upper case and it will be found. However, any globbed (wildcard) ls command requires upper case characters. Individual datasets can be listed in either upper or lower case. To be safe, it is a good idea to use upper case on all list requests.

  • As mentioned above, partitioned datasets (PDS) are treated as directories. the long list form ls -l can be used to list member statistics, if statistics exist.

  • The ls accepts dataset names prefixed either by // or /-/. The second form should be used for the few sftp clients that do not allow a double slash to sent to the server.

Example: Listing datasets

sftp> cd //USER
sftp> ls -al     1
Volume  Referred  Ext  Tracks    Used Recfm Lrecl BlkSz Dsorg  Dsname
WORK84 2008/09/05   1       1       1  FB      80 27920  PS    USER.AFILE.TXT                              
WORK81 2008/09/08   1      30       ?  U        0  6144  PO-E  USER.COZ.LOADLIB                            
WORK81 2008/09/11   1      15       4  FB      80 27920  PO    USER.COZ.SAMPJCL                            
WORK84 2008/09/11   1       1       1  U        0  6144  PS    USER.COZ.TEST.SEQ                           
WORK81 2008/09/09   1      15       3  FB      80 27920  PO    USER.COZ.TESTJCL

sftp> cd //USER     2
sftp> ls CO*
COZ.LOADLIB/          COZ.SAMPJCL/          COZ.TEST.SEQ          COZ.TESTJCL/ 

sftp> ls //USER/CO*     3
//USER/COZ.LOADLIB/   //USER/COZ.SAMPJCL/   //USER/COZ.TEST.SEQ
//USER/COZ.TESTJCL/  

sftp> ls //USER.CO*     4
Couldn't get handle: Failure
Can't ls: "//USER.CO*" not found

sftp> ls //     5
Couldn't stat remote file: No such file or directory
Can't ls: "//" not found

sftp> cd //user
sftp> ls co*     6
Can't ls: "//USER/co*" not found
sftp>
1

The long form of the list command ls -al will list detailed information from the catalog about each dataset.

2

Relative listing requests can be performed by first navigating to the desired level, then issuing the list request without any prefix.

3

When using wildcards, the desired result can be achieved by using a slash (/ in place of the traditional level separator (.).

4

Due to existing sftp client design, this list request would require the entire catalog to be searched, then filtered with the pattern USER.CO*. It is therefore disallowed.

5

Lists that would involve the entire catalog are not supported. The openssh sftp client reports this as shown.

6

The same command with a lower case pattern will fail (as described above).

Example: Listing a PDS directory

...
sftp> cd //user.coz.sampjcl     1
sftp> ls -al     2
Name           Size  Created         Changed          ID
@@README 
BPXBATCH         13 2008/04/04 2008/04/04 17:18:09  USER   
BPXBATSL         16 2008/04/03 2008/04/03 10:36:52  USER   
COZCFGD          65 2008/03/27 2008/05/12 14:28:54  USER   
COZPROC          30 2008/03/27 2008/03/27 11:54:48  USER   
DTLSPAWN         40 2008/05/05 2008/05/05 09:31:08  USER   
GPGDSN           15 2008/05/05 2008/05/05 10:40:05  USER   
GREPDSN  
GREPSED          12 2008/05/05 2008/05/05 09:30:51  USER   
OFFLDSMF 
RUNCOZ           20 2008/03/27 2008/05/12 14:08:02  USER   
RUNCOZ2          15 2008/05/05 2008/05/05 10:02:51  USER   
RUNCOZ3           8 2008/05/05 2008/05/06 08:50:37  USER   
RUNSPAWN         54 2008/05/12 2008/05/12 14:25:37  USER   
RUNSPWN2         20 2008/05/12 2008/05/12 13:19:05  USER   
TDIRK            18 2008/04/03 2008/04/03 10:19:20  USER   
WGET2DSN
1

The cd command is used to make a PDS the current working "directory".

2

The ls -al command (long list form) is used to display the members of the PDS, including available statistics.

3.4 Working with POSIX files

This section describes how to use the Co:Z implementation of sftp with POSIX files (HFS, zFS) on z/OS. Standard sftp implementations (including IBM's ported tools version) support only binary mode file transfers. The Co:Z implementation provides binary transfer mode by default, but also supports text mode transfers. Text mode transfers are controlled via the following options:

  • mode: when set to text causes file transfers to be text based.

  • clientcp and servercp: When text mode is active, these settings determine the codepage translation that will take place. The default client code page is ISO8859-1. The default server code page is the current z/OS locale.

  • linerule: When text mode is active, this setting determines how line separators are converted between the client and server.

Transferring Files

The get and put commands are used to transfer POSIX files (either on HFS or zFS filesystems).

The options (listed above) that have been previously set via the ls /+option=value are in effect for any given transfer. All other options (used for dataset support) are ignored for POSIX file transfers.

Example: Get a text POSIX file

sftp> ls /+mode=text,clientcp=UTF-8     1
/+mode=text,clientcp=UTF-8  
sftp> ls /+     2
/+/clientcp=UTF-8     /+/mode=text          /+/servercp=IBM-1047
sftp> get .ssh/sftp-server.rc     3
Fetching /u/user/.ssh/sftp-server.rc to sftp-server.rc
/u/user/.ssh/sftp-server.rc                100%  234     0.2KB/s   00:00    
sftp>
1

The default transfer mode of binary is overridden and set to text. Additionally, the client code page is explicitly set to UTF-8.

2

Displays the active options. Note that the server code page, if not explicitly set, defaults to the current z/OS locale.

3

The get command requests the transfer of the POSIX file using the options in effect.

Example: Put a text POSIX file

sftp> put sftp-server.rc .ssh     1
Uploading sftp-server.rc to /home/user/.ssh/sftp-server.rc
sftp-server.rc                             100%  234     0.2KB/s   00:00    
sftp>
1

The client text file sftp-server.rc is put to the remote directory .ssh under the current working remote directory. The active file transfer options are used.