-
May 3rd, 2010, 09:57 AM
#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.GetRequestStream();"
i am using the following 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.....
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|