Can FtpWebRequest upload ASCII row lengths larger than 256 characters? My 2091 character rows are truncating

63 Views Asked by At

I have a .NET Core 3.1 web app that was calling a BAT/Command file process to upload a text file to a remote directory. It was working fine, but I was tasked with changing the FTP process to use Ftp Web Request. The file transfer uploads to the mainframe directory with the code below, but it truncates at 253 characters for each row when I send it in ASCII format. If I send it in binary format, it does not truncate the rows, but the remote routine that sweeps the file into a print queue does not work. The file needs to be sent in ASCII format.

Each row can be varying lengths. How can I get the whole row to upload correctly in ASCII format without truncating the row?

The code:

                string UserId = "xxx???1";
                string Password = "xxx?????";
                string ForUpload = @"\\Serverxx\ExportChecks\Payment\Payments.txt";
                string remotePrintPath = "ftp://1.0.0.1:21/" + "'tevxxxp.laser.xnn.payments.dtl(+1)'";
                try
                {
                    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(remotePrintPath);
                    request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
                    request.Method = WebRequestMethods.Ftp.UploadFile;
                    request.Credentials = new NetworkCredential(UserId, Password);
                    // Set the data transfer type.
                    request.UseBinary = false;
                    // Copy the contents of the file to the request stream.  
                    StreamReader sourceStream = new StreamReader(ForUpload);
                    byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                    //request.ContentLength = fileContents.Length;
                    sourceStream.Close();
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(fileContents, 0, fileContents.Length);
                    requestStream.Close();
                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();                    
                    response.Close();
                }

Example of the command file (called by the BAT file) upload which works fine:

open 1.0.0.1
xxx???1
xxx????
quote site chkptint=0
quote site conddisp=delete
quote site recfm=fb lrecl=2091 blksize=20910
quote site cyl secondary=10 primary=10
quote site dataclass=stripe
put \\Serverxx\ExportChecks\Payment\Payments.txt 'tevxxxp.laser.xnn.payments.dtl(+1)'
quit
0

There are 0 best solutions below