WebException message vs. Response.StatusDescription on FtpWebRequest

Recently one of the reader asked an interesting question, he was using FtpWebRequest with MakeDirectory method, if directory already exist then application received the WebException with message.“The remote server returned an error: (550) File unavailable (e.g., file not found, no access).”. This exception message appears to be very generic and not helping the user to figure out what causes this request to fail. The reason is exception messages are generally set by framework implementation, because they also need to be localized on different language versions.

In such case if FtpWebRequest user want to diagnose and figure out why request actually failed, he could access the actual response message from server using ((FtpWebResponse)e.Response).StatusDescription property. Your actual code would look like as below

   .  .  . . . . .  .
   WebResponse response = request.GetResponse();
 . . . . . . . . . .
catch(WebException e)
        String status = ((FtpWebResponse)e.Response).StatusDescription;

This posting is provided “AS IS” with no warranties, and confers no rights

Comments (1)

  1. This is a current compile of the team’s existing blogs on FtpWebRequest. I am going to update it periodically