Empty files being uploaded to Mainframe, 2 connections being opened?

Dec 2, 2013 at 7:51 PM
I'm connecting to a mainframe and sending a file to a dataset. When I run my code, my mainframe coworker tells me that the file is created, but is empty. Also, he noticed that the record length was defined as 80, when I executed the "site lrecl=60" command prior to the transfer.

I noticed that there are two instances of the connecting messages being displayed (220-B1FTPD1 IBM FTP CS V1R13 at {host}, 19:24:42 on 2013-12-02.). It appears to be making one connection, executing my statements, and then opening a second connection to do the transfer. This second connection closes afterwards.
220-B1FTPD1 IBM FTP CS V1R13 at {host}, 19:24:42 on 2013-12-02.
220 Connection will close if idle for more than 5 minutes.
USER {user}
331 Send password please.
PASS <omitted>
230 {user} is logged on.  Working directory is "{user}.".
FEAT
211 no Extensions supported
Text encoding: System.Text.ASCIIEncoding
site recfm=fb
200 SITE command was accepted
site lrecl=60
200 SITE command was accepted
220-B1FTPD1 IBM FTP CS V1R13 at {host}, 19:24:43 on 2013-12-02.
220 Connection will close if idle for more than 5 minutes.
USER {user}
331 Send password please.
PASS <omitted>
230 {user} is logged on.  Working directory is "{user}.".
Text encoding: System.Text.ASCIIEncoding
PWD
257 "'{user}.'" is working directory.
CWD '{user}.'
250 "{user}." is the working directory name prefix.
TYPE I
200 Representation type is Image
SIZE 'MY.FILE.NAME(+1)'
501 command aborted -- FTP server not configured for SIZE
EPSV
229 Entering Extended Passive Mode (|||23100|)
STOR 'MY.FILE.NAME(+1)'
125 Storing data set MY.FILE.NAME.G0008V00
Disposing FtpSocketStream...
250 Transfer completed successfully.
QUIT
221 Quit command received. Goodbye.
Disposing FtpClient object...
Disposing FtpSocketStream...
Disposing FtpClient object...
QUIT
221 Quit command received. Goodbye.
Disposing FtpSocketStream...
try
            {
                var fileBytes = File.ReadAllBytes(tempFile);
                FtpTrace.AddListener(new ConsoleTraceListener());
                using (var client = new FtpClient())
                {
                    client.Host = "host";
                    client.Credentials = new NetworkCredential("user", "pass");
                    client.Port = 21;
                    client.Execute("site recfm=fb");
                    client.Execute("site lrecl=60");

                    using (var writeStream = client.OpenWrite(@"'my.file.name(+1)'"))
                    {
                        writeStream.Write(fileBytes, 0, fileBytes.Length);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
Coordinator
Dec 2, 2013 at 9:37 PM
It's the thread safe data connections, covered in the docs and on the front page. Set the EnableThreadSafeDataConnections property to false if you don't want the described behavior.
Dec 3, 2013 at 6:12 PM
Thanks! That did the trick.

Also, the "empty" files were just appearing that way. When he did "hex on" after displaying the file on the mainframe, all of the data was there.