title: 550 error when attempting to upload file via FTP in C# on remote server
body: <p>The below code works when run against a server in our internal network. When I change the credentials to reflect a server outside of our network, I get a 550 error in response. When I catch the exception like so:</p>
  
  <pre><code>try { 
      requestStream = request.GetRequestStream();
      FtpWebResponse resp = (FtpWebResponse)request.GetResponse();
  
  }
  catch(WebException e) {
      string status = ((FtpWebResponse)e.Response).StatusDescription;
      throw e;
  }
  </code></pre>
  
  <p>status has a value of:
  "550 Command STOR failed\r\n"</p>
  
  <p>I can successfully upload a file using the same credentials using a client such as Filezilla. I have already tried using SetMethodRequiresCWD() as other answers have suggested and this did not work for me.</p>
  
  <p>Here is the code, which receives a list of strings that each contain a full path to a file.</p>
  
  <pre><code>private void sendFilesViaFTP(List&lt;string&gt; fileNames) {
      FtpWebRequest request = null;
  
      string ftpEndPoint = "ftp://pathToServer/";
      string fileNameOnly; //no path
      Stream requestStream;
  
      foreach(string each in fileNames){
          fileNameOnly = each.Substring(each.LastIndexOf('\\') + 1);
  
          request = (FtpWebRequest)WebRequest.Create(ftpEndPoint + fileNameOnly);
          request.Method = WebRequestMethods.Ftp.UploadFile;
  
          request.Credentials = new NetworkCredential("username", "password");
  
          StreamReader fileToSend = new StreamReader(each);
  
          byte[] fileContents = Encoding.UTF8.GetBytes(fileToSend.ReadToEnd()); //this is assuming the files are UTF-8 encoded, need to confirm
          fileToSend.Close();
          request.ContentLength = fileContents.Length;
  
          requestStream = request.GetRequestStream();
  
  
          requestStream.Write(fileContents, 0, fileContents.Length);
          requestStream.Close();
  
          FtpWebResponse response = (FtpWebResponse)request.GetResponse(); //validate this in some way?
          response.Close();
      }
  }
  </code></pre>