0

My software i designed uploads files using ftp to my sever I'm using the ftpwebrequest to do all uploading. When uploading a file 700mb it uploads about 500mbs then stops, it works fine when uploading smaller files the smaller files upload successfully but it just want work properly on large files. I have the uploading done in a background worker that reports the upload progress to a progress bar on the main client. When the background worker completes it executes the background worker completed function. The background worker completed function gets executed but the upload never completes and the progress bar is stuck at about 65 percent its like the client just stops uploading and executes the background worker completed function as though it completed uploading. What could be going wrong here the upload doesn't complete and the file dose not appear on the server here is the code that dose the uploading

void UploadFileInBackground_DoWork(object sender,DoWorkEventArgs e)
{
        byte[] data;
        int packetsize = 1024 * 8;

        string Destination = UploadURI + cattext + "/" + ID + ".obj";
        string source = DialogBrower.FileName;
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Destination);
        request.Credentials = new NetworkCredential("user", "pass");
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.UsePassive = true;
        request.UseBinary = true;
        request.KeepAlive = false;
        using (FileStream fs = new FileStream(source, FileMode.Open, FileAccess.Read))
        {
            try
            {
                long filesize = fs.Length;
                long sum = 0;
                int count = 0;
                data = new byte[packetsize];
                Stream reqStream = request.GetRequestStream();
                float totalpackits = filesize / packetsize;
                float weightofpackit = 100 / totalpackits;
                float percentage = 0;
                while (sum < filesize)
                {
                    List<string> statusparms = new List<string>();
                    count = fs.Read(data, 0, packetsize);
                    reqStream.Write(data, 0, count);
                    sum += count;
                    percentage += weightofpackit;
                    int percentagetotal = Convert.ToInt32(Math.Round(percentage));
                    statusparms.Add(sum.ToString());
                    statusparms.Add(filesize.ToString());
                    UploadFileInBackground.ReportProgress(percentagetotal, statusparms);
                }
                reqStream.Close();
                uploadedname = uploadingname;
            }
            finally
            {
                fs.Dispose();
                data = null;
            }
        }
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 11 '12 at 00:47

2 Answers2

0

Please try this instead:

request.UseBinary = false;
Truong Anh Tuan
  • 79
  • 1
  • 11
0

let's try this

request.KeepAlive = false;

to

request.KeepAlive = true;
Kelvin Wong
  • 41
  • 1
  • 2