Can Rebex SFTP convert to ASCII a file from a mainframe SFTP server?

0 votes
asked Jul 26, 2013 by marybeihl (120 points)
edited Jul 26, 2013

I see from question 747 that the SFTP client has to do the transformation.

Can the Rebex do the transformation from EBCDIC to ASCII?

If so, what properties do I have to set to what values?

We've tried ServerType of Unknown and TransferType of ASCII but that didn't work.

Applies to: Rebex SFTP

1 Answer

0 votes
answered Jul 26, 2013 by Lukas Pokorny (126,950 points)
edited Jul 26, 2013

Although Rebex SFTP itself doesn't support EBCDIC to ASCII transformation, .NET's System.Text.Encoding object does and can be used with Rebex SFTP easily.

To download an EBCDIC file using the Sftp object and save it as ASCII, use the following code:

var sftp = new Sftp();

// create a memory stream
var ms = new MemoryStream();

// use binary transfer type
sftp.TransferType = SftpTransferType.Binary;

// download an EBCDIC file into the memory stream
sftp.GetFile(remoteFile, ms);

// get an instance of EBCDIC charset (="ibm037")
var ebcdic = System.Text.Encoding.GetEncoding("ibm037");

// convert the EBCDIC contents of the memory stream to a .NET string
string text = ebcdic.GetString(ms.ToArray());

// save the string as ASCII
File.WriteAllText(localFile, text, System.Text.Encoding.ASCII);