Click here to Skip to main content
14,692,225 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When large data uploading my FTP server. get
The underlying connection was closed: An unexpected error occurred on a receive


What I have tried:

<pre> var ftpClient = (FtpWebRequest)WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}", ftpAdress, folder)));
                ftpClient.Credentials = new NetworkCredential(user, pass);
                ftpClient.Method = WebRequestMethods.Ftp.UploadFile;
                ftpClient.UseBinary = true;
                ftpClient.KeepAlive = true;
                ftpClient.Timeout = 10000000;
                ftpClient.ReadWriteTimeout = 10000000;
                ftpClient.UsePassive = true;

                var fileInfo = new FileInfo(dbPath);
                ftpClient.ContentLength = fileInfo.Length;


                var buffer = new byte[fileInfo.Length];
                var bytes = 0;
                int totalBytes = (int)fileInfo.Length;
                  fs = fileInfo.OpenRead();
                  rs = ftpClient.GetRequestStream();
                while (totalBytes > 0)
                {
                    bytes = fs.Read(buffer, 0, buffer.Length);
                    rs.Write(buffer, 0, bytes);
                    totalBytes = totalBytes - bytes;
                }
                //fs.Flush();
                fs.Close();
                rs.Close();
                   uploadResponse = (FtpWebResponse)ftpClient.GetResponse();
                uploadResponse.Close();
Posted
Comments
gggustafson 5-Apr-18 14:19pm
   
Have you tried Filezilla? I find that simple errors can be solved by using another method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900