How do I set the LRECL in C#.NET?

Posted by donde on Stack Overflow See other posts from Stack Overflow or by donde
Published on 2010-05-27T13:35:17Z Indexed on 2010/05/27 14:41 UTC
Read the original article Hit count: 205

Filed under:
|

I have been trying to ftp a dtl file from .net to, what I beleive, is an AS400. The error being reported back to me is: "One or more lines have been truncated" and the admin is saying the file is coming over with 256 lines that have variable length columns. I found this explanation online:

we have to establish defaults because no specifics about the file exist. The default RECFM is V and LRECL is 256. This means that SAS will scan the input record looking for the CR & LF to tell us that we are at the EOR. If the marker isn't found within the limit of the LRECL, SAS discards the data from the LRECL value to the end of the record and adds a message to the Log that "One or more lines have been truncated".

So I need to set the LRECL. How do I do this in C# .NET?

            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            ftp.Credentials = new NetworkCredential(user, pwd);

            ftp.KeepAlive = false;
            ftp.UseBinary = false;  
            ftp.Method = WebRequestMethods.Ftp.UploadFile;

            FileStream fs = File.OpenRead(inputfilepath + ftpfileName);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();

            Stream ftpstream = ftp.GetRequestStream();

            int i = 0;
            int intBlock = 1786;
            int intBuffLeft = buffer.Length;

            while (i < buffer.Length)
            {
                if (intBuffLeft >= 1786)
                {
                    ftpstream.Write(buffer, i, intBlock);
                }
                else
                {
                    ftpstream.Write(buffer, i, intBuffLeft);
                }
                i += intBlock;
                intBuffLeft -= 1786;
            }
           ftpstream.Close();

© Stack Overflow or respective owner

Related posts about c#

Related posts about ftp