How to FTP Variable Length Record Datasets

Note: This article is relevant only for users of IBM's mainframe operating system zOS

When FTP reads a dataset for transmission, the dataset access method will typically provide that data one record at a time, for record formats F or FB 80 datasets that's 80 byte chunks. For V or VS and VB or VBS datasets that's as many bytes as inicated in the RDW, the record header containing the record length information (for the VB and VBS datasets there's also a BDW describing the length of each block of records but we can ignore this here). With a normal ASCII FTP transfer, all EBCDIC data will be translated to ASCII and a CR-LF (carriage return, line feed) sequence will be appended to each record (note any RDW will not be included). The file when received on a PC will then be viewable just as any other PC text file. If the same file were now FTP'd back to the mainframe, the ASCII data would be converted to EBCDIC, the CR-LF sequence removed and the record written to the target dataset, for V and VB or VBS datasets that includes an RDW header. So where's the problem?

Consider the case where we wish to send binary data. In binary or Image mode FTP will do exactly the same as before but will not perform ASCII-EBCDIC translation and will not append a CR-LF sequence. If this was an EBCDIC text file from an FB 80 dataset we would need a PC EBCDIC editor, such as SPFLite, to view the data and we would need to tell the editor that the file consists of fixed length 80 byte records. Similarly when we binary FTP a format U (undefined) dataset we can FTP it back to the mainframe but we must manually set the correct block size.

In the case of variable length records we need to tell FTP to also transmit RDW (and BDW) information along with the data. We can do this with the SITE command i.e. a command specific to IBM mainframes. The command we wish to send is "SITE RDW". Note that if you were using the MS windows standard FTP client you would have to wrap this in a LITERAL command e.g "Literal SITE RDW". A typical MS Windows command sequence to FTP get zOS dataset 'SNYS.UNLOAD.OUTPUT' would then be:

Connected to
220-FTPD1 IBM FTP CS V1R4 at SNYS.NL, 13:12:32 on 2016-09-26.
220 Connection will close if idle for more than 5 minutes.
501 command OPTS aborted -- no options supported for UTF8
User ( snys01
331 Send password please.
230 SNYS01 is logged on.  Working directory is "SNYS01.".
ftp> cd 'snys.unload'
250 "SNYS.UNLOAD." is the working directory name prefix.
ftp> lcd d:\temp
Local directory now D:\Temp.
ftp> bin
200 Representation type is Image
ftp> Literal SITE RDW
200 SITE command was accepted
ftp> get output
200 Port request OK.
125 Sending data set SNYS.UNLOAD.OUTPUT
250 Transfer completed successfully.
ftp: 30574 bytes received in 0.06Seconds 493.13Kbytes/sec.

If you were using FileZilla as your FTP client, you can enter the SITE command through the "Enter Custom Command ..." option of the SERVER tab. You can then enter the SITE command in the pop-up dialogue box (without the LITERAL prefix). It's also good practise to set the transfer type to binary (instead of auto), this is on the TRANSFER tab.