Click here to Skip to main content
14,573,882 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
I need to upload a file to ftp in c#. While uploading its giving me this error.
Cannot send a content-body with this verb-type. Below is my code

private void btnUpload_Click(object sender, EventArgs e)
       {

           //Load the file
           string filePath = txtFileName.Text;
           FileStream stream = File.OpenRead(filePath);
           byte[] buffer = new byte[stream.Length];

           stream.Read(buffer, 0, buffer.Length);
           stream.Close();

           //Upload file
           Stream reqStream = request.GetRequestStream();//request is declared globally
           reqStream.Write(buffer, 0, buffer.Length);
           reqStream.Close();

           MessageBox.Show("Uploaded Successfully");


       }
Posted
Comments
YAIR-I 28-Mar-13 3:21am
   
Request declared globally as what?
Zoltán Zörgő 28-Mar-13 3:29am
   
Well, than probably the request object is not well configured. Note: don't use "globally" declared objects for such purposes. It is bad practice. A request is typically a transient object.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100