This project is read-only.

Timed out trying to read data from the socket stream Exeception while upload file larger than 40MB

Jul 26, 2013 at 8:42 PM
Edited Jul 26, 2013 at 8:44 PM
Below is my code snippets
public void UploadFileFTP(string url, string filename)
    {

        long SentBytes = 0;

        FileInfo fileInf = new FileInfo(filename);

        long FileSize = new FileInfo(filename).Length;

        string finalurl = url + "/" + fileInf.Name;

        Uri uriaddress = null;

        using (FtpClient obj_FTP_Client = new System.Net.FtpClient.FtpClient())
        {
            obj_FTP_Client.Host = "www.xyx.com";
            obj_FTP_Client.Credentials = new NetworkCredential("demoaccount","password");
            obj_FTP_Client.DataConnectionEncryption = true;
            obj_FTP_Client.DataConnectionType = FtpDataConnectionType.AutoPassive;
            //obj_FTP_Client.EncryptionMode = FtpEncryptionMode.Explicit;
            obj_FTP_Client.ReadTimeout=36000;


            using (Stream ostream = obj_FTP_Client.OpenWrite("/asystemconsulting/Jul-26-2013/02:02/Cribwolf/03 - Rumaal.mp3"))
            {
                try
                {
                    int buffLength = 2048;
                    byte[] buff = new byte[buffLength];
                    FileStream fs = fileInf.OpenRead();

                    // Read from the file stream 2kb at a time
                    int BytesRead = fs.Read(buff, 0, buffLength);

                    while (BytesRead != 0)
                    {
                        // Write Content from the file stream to the FTP Upload Stream
                        ostream.Write(buff, 0, BytesRead);

                        SentBytes += BytesRead;

                        BytesRead = fs.Read(buff, 0, buffLength);

                   }
                    fs.Close();
                    ostream.Close();

                }
                finally
                {

                    ostream.Close();
                }
            }

        }











    }
Please help me on this .
when control reach at ostream.Close(); line it hangs for a minutes and return retrun exception message " Timed out trying to read data from the socket stream".
Jul 26, 2013 at 9:51 PM
Take the first ostream.Close() out, you don't need it. The one in the finally block will always be called, as it stands now it's being called twice. Also, please submit a transaction log which can be created using the FtpTrace static class. Refer the the Debug.cs code example for your options on logging.
Jul 26, 2013 at 9:52 PM
Edited Jul 26, 2013 at 9:53 PM
It's also possible the server may be closing the connection during the transfer. I've seen a few servers out there that will terminate the control connection due to inactivity even thought they aren't supposed to. Most notably, IIS.
Jul 27, 2013 at 2:22 PM
Edited Jul 27, 2013 at 4:54 PM
jptrosclair,

Replacing ostream.Close() from try catch block did not effect it is showing same exception message.,it hanged for some time and show same exception as above mentioned "Timed out trying to read data from the socket stream".
Jul 28, 2013 at 4:51 PM
How about that transaction log and does it exhibit the same behavior with any other FTP client, say FileZilla or [insert your favorite FTP client]?