problem with uploading large xml file on ftp in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashu2409
    New Member
    • Oct 2009
    • 2

    #1

    problem with uploading large xml file on ftp in ASP.NET

    Hi,

    I am trying to upload a large xml file (around 500 MB) on ftp location,but i

    am getting this error---

    it works fine upto 250 MB file

    The underlying connection was closed: An unexpected error occurred on a

    receive.

    i am getting the error on this line:-
    " Stream strm = ftpRequest.GetR equestStream(); "

    i am using the following code:-
    Code:
                   string upd_file = "ftp://" + FTPHost + "/" + FTPFolder + "/" + 
    
    "JJH.xml";
                    FtpWebRequest ftpRequest;
                    FtpWebResponse ftpResponse;
    
                     FileInfo fileInf = new FileInfo(file_name);
                        //Settings required to establish a connection with the 
    
    server
                        ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new 
    
    Uri(upd_file));
                        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                        ftpRequest.Proxy = null;
                        ftpRequest.UseBinary = true;
                        ftpRequest.UsePassive = true;
                        ftpRequest.Credentials = new NetworkCredential(username, 
    
    password);
                        ftpRequest.Timeout = int.MaxValue;
                        ftpRequest.ReadWriteTimeout = int.MaxValue;
                        ftpRequest.KeepAlive = false;
                        ftpRequest.ContentLength = fileInf.Length;
                       
    
                          // The buffer size is set to 2kb
                          int buffLength = 100000;
                          byte[] buff = new byte[buffLength];
                          int contentLen;
    
                        // Opens a file stream (System.IO.FileStream) to read  
    
    the file to be uploaded
                        FileStream fs = fileInf.OpenRead();
    
                        // Stream to which the file to be upload is written
                        Stream strm = ftpRequest.GetRequestStream();
    
                        // Read from the file stream 2kb at a time
                        contentLen = fs.Read(buff, 0, buffLength);
    
                        // Till Stream content ends
                        while (contentLen != 0)
                        {
                            // Write Content from the file stream to the 
                            // FTP Upload Stream
                            strm.Write(buff, 0, contentLen);
                            contentLen = fs.Read(buff, 0, buffLength);
                        }
    
                        // Close the file stream and the Request Stream
                        strm.Close();
                        fs.Close();

    Please help me----
    i have tried everything.....
    Last edited by Frinavale; May 3 '10, 08:42 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    Check out this article on MSDN. It's a setting that needs to be set in your web.config file

    Comment

    Working...