Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
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

 
Share this answer
 

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