0 votes
by (120 points)
edited

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
by (148k points)
edited

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();
sftp.Connect(...);
sftp.Login(...);

// 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);
...