Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:12:16+00:00 2026-06-01T20:12:16+00:00

I was uploading my file using below code,it works fine but some time it

  • 0

I was uploading my file using below code,it works fine but some time it throws this error”The underlying connection was closed: The server committed a protocol violation” and stop the process ,when i run it again it upload file with out any issue.

One thing i noticed,if i run this process to upload multiple files then i get this error sometime,if i do less than 5 files then it works fine,any idea where and what i have to look in to it.

I was searchin google nothing found solid solution for this,even one of the msdn blog saying its a bug in FTPwebrequest but not sure.

Environment : C# 4.0, IIS FTP Server.

Thanks in Advance

                FileInfo fileInf = new FileInfo(filename);
                FtpWebRequest reqFTP;

                // Create FtpWebRequest object from the Uri provided
                reqFTP = (FtpWebRequest)FtpWebRequest.Create
                         (new Uri(path + fileInf.Name));


                // Provide the WebPermission Credintials
                 reqFTP.Credentials = new NetworkCredential(user, pwd);

                // By default KeepAlive is true, where the control connection
                // is not closed after a command is executed.
                reqFTP.KeepAlive = false;


                // Specify the command to be executed.
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

                // Specify the data transfer type.
                reqFTP.UseBinary = true;
                reqFTP.Timeout = -1;
                reqFTP.UsePassive = true;


                // Notify the server about the size of the uploaded file
                reqFTP.ContentLength = fileInf.Length;

                // The buffer size is set to 2kb
                int buffLength = 4096;
                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();


                try
                {
                    // Stream to which the file to be upload is written
                    Stream strm = reqFTP.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();
                }

Answer

reqFTP.KeepAlive = false; to “True” to get rid of the error in my case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:12:17+00:00Added an answer on June 1, 2026 at 8:12 pm

    Changed from reqFTP.KeepAlive = false; to “reqFTP.KeepAlive = True;” to get rid of the error

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently looking in to some file uploading using Java Server Faces. I've
Hi am using apache commons upload for uploading files File file=this.getFile();//getter method for the
I'm using a code below to upload file (tens of MB) in streaming mode.
I'm uploading a file using jQuery through Ajax. I'm submitting some form elements also,
I am Uploading a file into a webserver using File upload API it works
When uploading an excel file I am receiving this error, can anyone help me?
I am uploading files using HttpWebRequest to an ASP.Net MVC application but, for some
Actually I'm creating an application for uploading file using JSF. But whenever I upload
I am uploading file using jQuery uploadify plugin. Each time I upload a file,
I would like to do below validations for single file uploaded using jQuery Uploadify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.