title: Status Code from FTPWebRequest.GetResponse() method
body: <p>This is slightly tricky. </p>
  
  <p>I am uploading files to FTP asynchronously. 
  After uploading each file I am checking the status of the upload operation for that file. This can be done with StatusCode property of the FtpWebResponse object for that request.
  The code snippet is as give below.</p>
  
  <pre><code>FileStream fs = File.Open(fileName, FileMode.Open);
  
  while ((iWork = fs.Read(buf, 0, buf.Length)) &gt; 0)
      requestStream.Write(buf, 0, iWork);
  
  requestStream.Close();
  
  FtpWebResponse wrRet = ((FtpWebResponse)state.Request.GetResponse());
  </code></pre>
  
  <p>There are about 37 StatusCode values as per <a href="http://msdn.microsoft.com/en-us/library/system.net.ftpstatuscode.aspx" rel="noreferrer">msdn</a>. I am unaware as to which of these status code values will assure that the file is uploaded successfully. Some of them I used in my code  to check for success are :</p>
  
  <pre><code>wrRet.StatusCode == FtpStatusCode.CommandOK 
  wrRet.StatusCode == FtpStatusCode.ClosingData
  wrRet.StatusCode == FtpStatusCode.ClosingControl
  wrRet.StatusCode == FtpStatusCode.ConnectionClosed
  wrRet.StatusCode == FtpStatusCode.FileActionOK
  wrRet.StatusCode == FtpStatusCode.FileStatus
  </code></pre>
  
  <p>But I am unaware of the rest. I need to be sure about these codes because based on the failure or success of the upload operation I have other dependent operations to be carried out. A wrong condition can affect the remaining code. 
  Another thought that crossed my mind was to simply put the above code into a try..catch and not depend on these status codes. With this I would not be depending on the status codes and assuming that any failure will always be directed to the catch block. Kindly let me know if this is the right way.</p>