title: Using ftp in C# to send a file
body: <p>I'm trying to send a file using ftp.  I have the following code:</p>
  
  <pre><code>string server = "x.x.x.x";  // Just the IP Address 
  
  FileStream stream = File.OpenRead(filename);
  byte[] buffer = new byte[stream.Length];
  
  WebRequest request = WebRequest.Create("ftp://" + server);
  request.Method = WebRequestMethods.Ftp.UploadFile;            
  request.Credentials = new NetworkCredential(username, password);
  
  Stream reqStream = request.GetRequestStream(); // This line fails
  reqStream.Write(buffer, 0, buffer.Length);
  reqStream.Close();
  </code></pre>
  
  <p>But when I run it, I get the following error:</p>
  
  <p>The requested URI is invalid for this FTP command.</p>
  
  <p>Please can anyone tell me why?  Am I using this incorrectly?</p>