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.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.